<?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: TransactionManager.StartTransaction() throws NullReferenceException in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252239#M20479</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does your active doc have a valid database? Otherwise it could be the AutoCAD start window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jan 2020 14:01:19 GMT</pubDate>
    <dc:creator>Alfred.NESWADBA</dc:creator>
    <dc:date>2020-01-15T14:01:19Z</dc:date>
    <item>
      <title>TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9248909#M20474</link>
      <description>&lt;P&gt;Inside of DB.Object_Modified event handler I'm examining the modified object. Sometimes I need to retrieve another object based on an ObjectId, thus I use transaction. 90% of times it works but sometimes&amp;nbsp;TransactionManager.StartTransaction() method throws a NullReferenceExeption internally (stack trace below). Any idea how could I prevent this from happening (is there any property of DBObject, Document or anything else I could use to check if I can safely start a transaction?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;System.NullReferenceException: Object reference not set to an instance of an object.&lt;BR /&gt;at Autodesk.AutoCAD.Runtime.Interop.CheckNull(IntPtr returnValue)&lt;BR /&gt;at Autodesk.AutoCAD.ApplicationServices.TransactionManager.StartTransaction()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eventually I could use a try-catch block but I'm looking for a more efficient way.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 09:09:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9248909#M20474</guid>
      <dc:creator>adam.krug</dc:creator>
      <dc:date>2020-01-14T09:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9249014#M20475</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;see if "&lt;SPAN&gt;StartOpenCloseTransaction&lt;/SPAN&gt;" transaction helps in your case. refer&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2012/08/the-right-tools-for-the-job-autocad-part-5.html" target="_blank"&gt;https://adndevblog.typepad.com/autocad/2012/08/the-right-tools-for-the-job-autocad-part-5.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 10:11:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9249014#M20475</guid>
      <dc:creator>Virupaksha_aithal</dc:creator>
      <dc:date>2020-01-14T10:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9249169#M20476</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/826400"&gt;@Virupaksha_aithal&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;In my case it didn't help but still thanks for pointing out on the&amp;nbsp;&lt;SPAN&gt;StartOpenCloseTransaction , very interesting read!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not sure what exactly is causing the problem, seems like the context for starting the transaction is sometimes not valid. Anyways, I decided to change my original approach: during Db_ObjectModified event handler I only add the modified objects on a list and examine them only after a command is finished, using&amp;nbsp;Doc_CommandEnded event handler. Then I also clean the list. Works.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 11:18:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9249169#M20476</guid>
      <dc:creator>adam.krug</dc:creator>
      <dc:date>2020-01-14T11:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9250196#M20477</link>
      <description>&lt;P&gt;I've run into issues where there is no active document, and the code still runs from a palette or other event.&lt;/P&gt;&lt;P&gt;Checking for a null document has helped with that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Document doc = CAD_App.DocumentManager.MdiActiveDocument;
if (doc == null) return;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 17:31:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9250196#M20477</guid>
      <dc:creator>timgrote</dc:creator>
      <dc:date>2020-01-14T17:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252205#M20478</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4276646"&gt;@timgrote&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case the ActiveDoc is not null, I'm getting the null reference exception inside of the StartTransaction() call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If ActiveDoc was null, I wouldn't be able to even reach StartTransaction()&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 13:52:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252205#M20478</guid>
      <dc:creator>adam.krug</dc:creator>
      <dc:date>2020-01-15T13:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252239#M20479</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does your active doc have a valid database? Otherwise it could be the AutoCAD start window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 14:01:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252239#M20479</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2020-01-15T14:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252675#M20480</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The NullReferenceException is probably related to an instance of TransactionManager or the instance of Database (or Document) the TransactionManager is got from.&lt;/P&gt;
&lt;P&gt;Try simply doing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using (var tr = new OpenCloseTransaction())
{
    // do your stuff with tr here
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 16:25:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/9252675#M20480</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-01-15T16:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: TransactionManager.StartTransaction() throws NullReferenceException</title>
      <link>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/11723545#M20481</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4424911"&gt;@adam.krug&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you make more clear about your approach (or a sample code) about using&amp;nbsp;&lt;SPAN&gt;Doc_CommandEnded event handler. I want to use that to modify object properties after a command finish.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 08:17:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transactionmanager-starttransaction-throws/m-p/11723545#M20481</guid>
      <dc:creator>quan_hm</dc:creator>
      <dc:date>2023-02-02T08:17:05Z</dc:date>
    </item>
  </channel>
</rss>

