<?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: Plugin bundle load fails and AutoCAD Crashes at startup in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796333#M18298</link>
    <description>&lt;P&gt;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all &lt;STRONG&gt;AcCoreAp.DocumentManager.MdiActiveDocument&lt;/STRONG&gt; can be &lt;STRONG&gt;null&lt;/STRONG&gt; while loading from BUNDLE&lt;/P&gt;
&lt;P&gt;So you have to check it.&lt;/P&gt;</description>
    <pubDate>Sun, 11 Oct 2020 14:17:33 GMT</pubDate>
    <dc:creator>Alexander.Rivilis</dc:creator>
    <dc:date>2020-10-11T14:17:33Z</dc:date>
    <item>
      <title>Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796175#M18295</link>
      <description>&lt;P&gt;Good day All,&lt;/P&gt;&lt;P&gt;I have developed a plugin for AutoCAD and it works fine when i do netload.&lt;/P&gt;&lt;P&gt;But when i put the bundle folder&amp;nbsp; in one of&amp;nbsp; the below locations, AutoCAD crashes at startup with&lt;/P&gt;&lt;P&gt;&lt;U&gt;"Fatal Error: Unhandled access violation Reading 0x0000 Exception at DEAAF94Dh"&lt;/U&gt;.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%APPDATA%/Autodesk/ApplicationPlugins.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- %ProgramFiles%/Autodesk/ApplicationPlugins.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-&amp;nbsp;%ProgramData%/Autodesk/ApplicationPlugins.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I followed the instructions&amp;nbsp;&amp;nbsp;&lt;A title="AutoCad Plugin Bundle Installation" href="https://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html" target="_blank" rel="noopener"&gt;&amp;lt;here&amp;gt;&lt;/A&gt;&amp;nbsp; to build the bundle folder and i also have a good working project build by myself.&lt;/P&gt;&lt;P&gt;I don't understand why it is crashing and will appreciate your assistance.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 11:22:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796175#M18295</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-11T11:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796258#M18296</link>
      <description>&lt;P&gt;Without knowing what your plugin does, seeing code, seeing the plugin bundle's configuration, it is really difficult to suggest anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that said, however, since you say AutoCAD crashes at startup, it sounds like at least one of the classes in the assembly or assemblies autoloaded into AutoCAD is ExtensionApplication (i.e. implemented IExenstionApplication interface and you have code does something in the Initialize() method, which runs the the assembly is loaded.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because you also say the plugin works fine when loaded with command "NETLOAD", so the question is: what your code des in the Initialize()? Is it possible the code there requires some AutoCAD resources, which may not be available when the assembly is loaded on AutoCAD startup, but available after AutoCAD fully started (when you manually "NETLOAD"). Is the code in Initialize() wrapped with try{...} catch{...} block?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, it is just a guess without knowing any details of your situation other than it crashes AutoCAD on startup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 13:15:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796258#M18296</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-10-11T13:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796292#M18297</link>
      <description>&lt;P&gt;Hi Norman,&lt;/P&gt;&lt;P&gt;Thank you for your prompt reply.&lt;/P&gt;&lt;P&gt;Sorry if was not that clear. This plugin is designed to do takeoff&amp;nbsp; and estimation in AutoCAD.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the Initialize() code:&lt;/P&gt;&lt;P&gt;public void Initialize()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Overrule = new PolylineOverrule();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; OverruleArea = new PolyAreaOverrule();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;OverrulePerimeter = new PolyPerimeterOverrule();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ForEdit = false;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;docMgr.DocumentCreated += DocumentCreated;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; docMgr.DocumentActivated += DocumentActivated;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;doubleObjectId =new ObjectId();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (ComdEndedHandled)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AcCoreAp.DocumentManager.MdiActiveDocument.CommandEnded -= CommandEnded;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AcCoreAp.DocumentManager.MdiActiveDocument.CommandEnded += CommandEnded;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ComdEndedHandled = !ComdEndedHandled;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (obModiHandled)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AcCoreAp.DocumentManager.MdiActiveDocument.Database.ObjectModified -= ObjectModified;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AcCoreAp.DocumentManager.MdiActiveDocument.Database.ObjectModified += ObjectModified;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; obModiHandled = !obModiHandled;&lt;/P&gt;&lt;P&gt;if (ObjErasedHandled)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AcCoreAp.DocumentManager.MdiActiveDocument.Database.ObjectErased -= ObjectErased;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AcCoreAp.DocumentManager.MdiActiveDocument.Database.ObjectErased += ObjectErased;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ObjErasedHandled = !ObjErasedHandled;&lt;/P&gt;&lt;P&gt;&amp;nbsp; foreach (Document doc in docMgr)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (ObjSelectedHandled)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doc.ImpliedSelectionChanged -= ObjectSelected;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doc.ImpliedSelectionChanged += ObjectSelected;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ObjSelectedHandled = !ObjSelectedHandled;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;}&lt;/P&gt;&lt;P&gt;DoubleClickObject.ChangeMacroCUI();&lt;/P&gt;&lt;P&gt;CustomizationSection cs = new CustomizationSection(DoubleClickObject.getMainCuiFile());&lt;/P&gt;&lt;P&gt;PartialCuiFileCollection pcfc = cs.PartialCuiFiles;&lt;/P&gt;&lt;P&gt;if (!pcfc.Contains(myCuiFile))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if (System.IO.File.Exists(myCuiFile))&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MyUtilities.LoadMyCui(myCuiFile);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;ids = new List();&lt;/P&gt;&lt;P&gt;ids2 = new List();&lt;/P&gt;&lt;P&gt;Commands.ActivateOverrule();&lt;/P&gt;&lt;P&gt;Objectgroupname = "";&lt;/P&gt;&lt;P&gt;takeOffSummary = new TakeOffSummary();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 13:49:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796292#M18297</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-11T13:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796333#M18298</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all &lt;STRONG&gt;AcCoreAp.DocumentManager.MdiActiveDocument&lt;/STRONG&gt; can be &lt;STRONG&gt;null&lt;/STRONG&gt; while loading from BUNDLE&lt;/P&gt;
&lt;P&gt;So you have to check it.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 14:17:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796333#M18298</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2020-10-11T14:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796336#M18299</link>
      <description>&lt;P&gt;Firstly, please post your code using the button "&amp;lt;/&amp;gt;" on top of the window, so that the code is readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, as I expected, you MUST wrap your code in Initialize() with try...catch... block, if the code does ANYTHING more than simple &lt;EM&gt;Editor.WriteMessage("\nHello World.");&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, usually AutoCAD is quite forgive-able to the code in Initialize(), that is, it usually silently swallows exceptions in Initialize() and carries on (with the loaded assembly being useless/failed loading).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your code, besides hooking up all sorts of event handler, the code also calls some actions, such as ActivateOverrule(),&amp;nbsp; checing main/partial cui and then possibly LoadMyCui(), ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any of these actions could causes the crash when your assembly is loaded, but I suspect checking CUI and loading custom CUI could be the offending source. You can verify by commenting out all these actions, or one by one and then try the autoloading on startup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is indeed because of one of the actions in Initialize() that causes the crash, then you sure postpone the/these action/actions in the Initialize() by handling Application.Idle(). That is, do the/these action/actions in Idle event handle, meaning Initialize() tells AutoCAD: run the actions(s) when AutoCAD startup finishes and becomes idle. To user, it still feels the extra work done in the Idle handle is part of startup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, You massive event handler hooking/removing code ONLY adds event handlers to the MdiActiveDocument when the assembly is loaded. Any document that opened after AutoCAD startup will not have these event handlers hooked up. How do make sure on AutoCAD startup, your target drawing (you want to takeoff work) is ALREADY OPEN when your assembly is to be loaded? Obviously, when in your testing/debugging with manually "NETLOAD", you likely always has your target drawing open, thus your plugin worked. But with autoloading plugin, when user double click AutoCAD icon to start it up, the target drawing is very possibly not the one opens on AutoCAD startup. Usually, you need to hook/removed the event handlers to all existing open drawings and all possible drawing to be opened later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 14:19:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796336#M18299</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-10-11T14:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796371#M18300</link>
      <description>&lt;P&gt;Thank you Alexander, will investigate it.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 15:06:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796371#M18300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-11T15:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Plugin bundle load fails and AutoCAD Crashes at startup</title>
      <link>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796433#M18301</link>
      <description>&lt;P&gt;Hi Norman,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much. it worked!.&lt;/P&gt;&lt;P&gt;I moved the document event handlers and methods to Application.idle() and everything is working fine.&lt;/P&gt;&lt;P&gt;Thank you again for your assistance.&lt;/P&gt;&lt;P&gt;I'm a beginner in programming and i learn day by day.&lt;/P&gt;&lt;P&gt;Here is the revised Initialize() code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public void Initialize()
        {


            try
            {

                Overrule = new PolylineOverrule();

                OverruleArea = new PolyAreaOverrule();

                OverrulePerimeter = new PolyPerimeterOverrule();
                ForEdit = false;
               
                 doubleObjectId = new ObjectId();
               
                Application.Idle += OnIdle;

                ids = new List&amp;lt;ObjectId&amp;gt;();
                ids2 = new List&amp;lt;ObjectId&amp;gt;();
               
                Objectgroupname = "";
                takeOffSummary = new TakeOffSummary();
            }
            catch(Autodesk.AutoCAD.Runtime.Exception ex)
            {
   
AcCoreAp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
            }


        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;and here is the OnIdle():&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void OnIdle(object sender, EventArgs e)
        {
            var doc = AcCoreAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
            {
                AcCoreAp.Idle -= OnIdle;
                docMgr.DocumentCreated += DocumentCreated;
                docMgr.DocumentActivated += DocumentActivated;
                Commands.ActivateOverrule();
                if (ComdEndedHandled)
                    doc.CommandEnded -= CommandEnded;
                else
                    doc.CommandEnded += CommandEnded;
                ComdEndedHandled = !ComdEndedHandled;

                if (obModiHandled)
                    doc.Database.ObjectModified -= ObjectModified;
                else
                    doc.Database.ObjectModified += ObjectModified;

                obModiHandled = !obModiHandled;

                if (ObjErasedHandled)
                    doc.Database.ObjectErased -= ObjectErased;
                else
                   doc.Database.ObjectErased += ObjectErased;

                ObjErasedHandled = !ObjErasedHandled;

                //foreach (Document doc in docMgr)
                //{
                    if (ObjSelectedHandled)
                        doc.ImpliedSelectionChanged -= ObjectSelected;
                    else
                        doc.ImpliedSelectionChanged += ObjectSelected;

                    ObjSelectedHandled = !ObjSelectedHandled;
                
                DoubleClickObject.ChangeMacroCUI();

                CustomizationSection cs = new CustomizationSection(DoubleClickObject.getMainCuiFile());

                PartialCuiFileCollection pcfc = cs.PartialCuiFiles;


                if (!pcfc.Contains(myCuiFile))
                {
                    if (System.IO.File.Exists(myCuiFile))
                        MyUtilities.LoadMyCui(myCuiFile);
                }

                doc.Editor.WriteMessage("\nTakeOff tools Loaded\n");
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 11 Oct 2020 16:01:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plugin-bundle-load-fails-and-autocad-crashes-at-startup/m-p/9796433#M18301</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-11T16:01:56Z</dc:date>
    </item>
  </channel>
</rss>

