title: C# VSTO word AddIn Throws value does not fall within expected error
body: <p>I am new to VSTO word Addin,the end goal is to check if the custom document property exists.Read all the available articles online with no breakthrough.</p>
  <p>Started of with this code</p>
  <pre><code>public void chk()
  {
     if (this.Application.ActiveDocument.CustomDocumentProperties[&quot;ObjectType&quot;].Value = 0)
     {
        MessageBox.Show(&quot;Please select an object&quot;);
     }
  }
  </code></pre>
  <p>This throws the error</p>
  <p><a href="https://i.stack.imgur.com/SvnIr.png" rel="nofollow noreferrer">Value does not fall within bounds error</a></p>
  <p>Modified the code to create a custom document property object as below and it gives me the same error on</p>
  <blockquote>
  <p>if(this.Application.ActiveDocument.CustomDocumentProperties[&quot;ObjectType&quot;].Value
  = 0)</p>
  </blockquote>
  <pre><code>public void chk()
  {
        dynamic properties = null;
        properties = this.Application.ActiveDocument.CustomDocumentProperties;
        properties.Add(&quot;Name&quot;,false,Office.MsoDocProperties.msoPropertyTypeString, &quot;ObjectType&quot;);
        properties.Add(&quot;LinkToContent&quot;,false, Office.MsoDocProperties.msoPropertyTypeBoolean,false);
        properties.Add(&quot;Type&quot;,false,Office.MsoDocProperties.msoPropertyTypeNumber, 0);
                     
        if(this.Application.ActiveDocument.CustomDocumentProperties[&quot;ObjectType&quot;].Value = 0)
        {
            MessageBox.Show(&quot;Please select an object&quot;);
         }
  }
  </code></pre>
  <p>Requesting you to suggest the steps to fix the issue. Please let me know if more information is required.</p>