<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: System.NullReferenceException: Object reference not set to an instance of an obj in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/10648974#M5472</link>
    <description>&lt;P&gt;NullReferenceException means that you are trying to use a reference variable whose value is Nothing/null . When the value is Nothing/null for the reference variable, which means that it is not actually holding a reference to an instance of any object that exists on the heap.&lt;BR /&gt;&lt;BR /&gt;string str = null;&lt;BR /&gt;str.ToUpper();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above &lt;A href="http://net-informations.com/faq/net/interview-questions.htm" target="_blank" rel="noopener"&gt;c#&lt;/A&gt; code throws a NullReferenceException at the second line because you can't call the instance method ToUpper() on a string reference pointing to null. So, check your code once again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Sep 2021 05:35:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-09-27T05:35:41Z</dc:date>
    <item>
      <title>System.NullReferenceException: Object reference not set to an instance of an obj</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750636#M5468</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I have the following lines of C# code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;foreach (ObjectId attID in titleBlock.AttributeCollection)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference attRef = (AttributeReference)attID.GetObject(OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;if (String.Equals(attRef.Tag, UserPreferences.Instance.ABC, StringComparison.OrdinalIgnoreCase))&lt;BR /&gt;{&lt;BR /&gt;vendorIP = false;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;I am trying to figure out why GetObject keeps throwing me the exception "System.NullReferenceException: Object reference not set to an instance of an obj." attID is not Null. The documentation for GetObject indicates that it is looking for and object with the objectID of attID in attID. That doesn't make sense to me. For the code I really only need attRef.Tag which is a string. I could circumvent the this exception by just getting the Tag from attID. I'm confused and would like to ask for some guidance on how to eliminate this exception. BTW I did not write this code myself and my C# skills are just intermediate. Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 15:53:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750636#M5468</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-24T15:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: System.NullReferenceException: Object reference not set to an instance of an</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750662#M5469</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transaction was started?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 16:01:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750662#M5469</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2019-04-24T16:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: System.NullReferenceException: Object reference not set to an instance of an</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750686#M5470</link>
      <description>&lt;P&gt;1) You can check &lt;CODE&gt; ObjectId.IsValid &lt;/CODE&gt; if this API property return true&lt;/P&gt;
&lt;P&gt;2) The recommended approach to access the object from its object id is use transaction, you can get basic understanding of this from &lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUID-50FD6118-B2D1-4313-A7D6-830794DFDEFA-htm.html" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;PseudoCode:&lt;/P&gt;
&lt;PRE style="color: #d1d1d1; background: #000000;"&gt;&lt;SPAN style="color: #e66170; font-weight: bold;"&gt;using&lt;/SPAN&gt;&lt;SPAN style="color: #d2cd86;"&gt;(&lt;/SPAN&gt;OpenCloseTransaction o &lt;SPAN style="color: #d2cd86;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;new&lt;/SPAN&gt; OpenCloseTransaction&lt;SPAN style="color: #d2cd86;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #b060b0;"&gt;{&lt;/SPAN&gt;
  &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;foreach&lt;/SPAN&gt;&lt;SPAN style="color: #d2cd86;"&gt;(&lt;/SPAN&gt;ObjectId attID &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;in&lt;/SPAN&gt; titleBlock&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;AttributeCollection&lt;SPAN style="color: #d2cd86;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #b060b0;"&gt;{&lt;/SPAN&gt;

   &lt;SPAN style="color: #9999a9;"&gt;//AttributeReference attRef = (AttributeReference)attID.GetObject(OpenMode.ForRead);&lt;/SPAN&gt;

   AttributeReference attRef &lt;SPAN style="color: #d2cd86;"&gt;=&lt;/SPAN&gt; o&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;GetObject&lt;SPAN style="color: #d2cd86;"&gt;(&lt;/SPAN&gt;attID&lt;SPAN style="color: #d2cd86;"&gt;,&lt;/SPAN&gt; OpenMode&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;ForRead&lt;SPAN style="color: #d2cd86;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;as&lt;/SPAN&gt; AttributeReference&lt;SPAN style="color: #b060b0;"&gt;;&lt;/SPAN&gt;

   &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;if&lt;/SPAN&gt; &lt;SPAN style="color: #d2cd86;"&gt;(&lt;/SPAN&gt;String&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;Equals&lt;SPAN style="color: #d2cd86;"&gt;(&lt;/SPAN&gt;attRef&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;Tag&lt;SPAN style="color: #d2cd86;"&gt;,&lt;/SPAN&gt; UserPreferences&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;Instance&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;ABC&lt;SPAN style="color: #d2cd86;"&gt;,&lt;/SPAN&gt; StringComparison&lt;SPAN style="color: #d2cd86;"&gt;.&lt;/SPAN&gt;OrdinalIgnoreCase&lt;SPAN style="color: #d2cd86;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #d2cd86;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #b060b0;"&gt;{&lt;/SPAN&gt;
    vendorIP &lt;SPAN style="color: #d2cd86;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #e66170; font-weight: bold;"&gt;false&lt;/SPAN&gt;&lt;SPAN style="color: #b060b0;"&gt;;&lt;/SPAN&gt;
   &lt;SPAN style="color: #b060b0;"&gt;}&lt;/SPAN&gt;
  &lt;SPAN style="color: #b060b0;"&gt;}&lt;/SPAN&gt;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 16:09:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8750686#M5470</guid>
      <dc:creator>moogalm</dc:creator>
      <dc:date>2019-04-24T16:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: System.NullReferenceException: Object reference not set to an instance of an</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8751070#M5471</link>
      <description>&lt;P&gt;Thank you very much! This worked and the code makes a lot more sense!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 18:51:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/8751070#M5471</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-24T18:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: System.NullReferenceException: Object reference not set to an instance of an obj</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/10648974#M5472</link>
      <description>&lt;P&gt;NullReferenceException means that you are trying to use a reference variable whose value is Nothing/null . When the value is Nothing/null for the reference variable, which means that it is not actually holding a reference to an instance of any object that exists on the heap.&lt;BR /&gt;&lt;BR /&gt;string str = null;&lt;BR /&gt;str.ToUpper();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above &lt;A href="http://net-informations.com/faq/net/interview-questions.htm" target="_blank" rel="noopener"&gt;c#&lt;/A&gt; code throws a NullReferenceException at the second line because you can't call the instance method ToUpper() on a string reference pointing to null. So, check your code once again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 05:35:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/system-nullreferenceexception-object-reference-not-set-to-an/m-p/10648974#M5472</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-27T05:35:41Z</dc:date>
    </item>
  </channel>
</rss>

