Through the Interface: Preventing a .NET module from being loaded by AutoCAD

Kean Walmsley

May 2015

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


« No muttering at the back! Reducing the background noise when sending commands to AutoCAD | Main | Announcing two new Autodesk developer blogs »

September 08, 2008

Preventing a .NET module from being loaded by AutoCAD

This is an interesting one that came up recently during an internal discussion:

During my module's Initialize() function, I want to decide that the module should not actually be loaded. How can I accomplish that?

The answer is surprisingly simple: if you throw an exception during the function, AutoCAD's NETLOAD mechanism will stop loading the application.

For an example, see this C# code:

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

namespace PreventLoad


  public class Commands

  : IExtensionApplication


    public void Initialize()


      // This will prevent the application from loading

      throw new Exception();


    public void Terminate(){}


    static public void TestCommand()


      Document doc =



        "\nThis should not get called."





Here's what happens when we attempt to load the application and then run the TEST command:

Command: FILEDIA

Enter new value for FILEDIA <1>: 0

Command: NETLOAD

Assembly file name: c:\MyApplication.dll

Command: TEST

Unknown command "TEST".  Press F1 for help.


TrackBack URL for this entry:

Listed below are links to weblogs that reference Preventing a .NET module from being loaded by AutoCAD:

blog comments powered by Disqus


10 Random Posts