Netload and plugin installation

Netload and plugin installation

jptallano
Enthusiast Enthusiast
722 Views
8 Replies
Message 1 of 9

Netload and plugin installation

jptallano
Enthusiast
Enthusiast

Hi,

I built a .NET dll for Autocad that loads and works fine on my machine, using the Netload command. But when I install my plugin on another machine, it won't work: its commands are not registered, they are unknown in Autocad. Netload does not display any error, as a matter of fact, it displays nothing. As far as I know, the issue seems to be related to Windows security stuff. What do you think?

0 Likes
Accepted solutions (1)
723 Views
8 Replies
Replies (8)
Message 2 of 9

ActivistInvestor
Mentor
Mentor

No commands, and no error usually result from an exception that occurs when your assembly is loaded. That could happen if your assembly is dependent on other assemblies that are not loadable on the target system, it could be an exception in your assembly in code that runs at startup. Does your assembly have an IExtensionApplication. If it does, you can put the code in the Initialize() method inside of try{} block, followed by a catch{} block that catches and displays any exceptions that are raised.

 

 

0 Likes
Message 3 of 9

norman.yuan
Mentor
Mentor

NETLOAD command not displaying anything could be anything, good or bad. If it is AutoCAD security issue (i.e. loaded from a location that is not trusted folder), AutoCAD should prompts its security warning PRIOR to the dll is loaded. If your user obtained your DLL via the Internet (downlaoded from somewhere, or you emailed to them), then Windows will automatically flag the downloaded the DLL (or any executable file, for that matter) as unsafe. If loaded into AutoCAD, AutoCAD will generate error message of failed loading. So the DLL obtained via the Internet needs to be unlocked before use.

 

Since you get nothing displayed after NETLOAD command, it is likely your code error, if your DLL implemented IExtensionApplication and does something bad in Initialize() implementation. Since you did not provide any details about your code and/or how users get it "installed", I stop guessing here.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 9

jptallano
Enthusiast
Enthusiast

Hi guys, and thanks for you answers.

So far, installation on another machine is done by retrieving the dll from a local network drive. I already tried moving it to a trusted Autocad location.

App indeed extends IExtensionApplication, and Initialize() code already implements try/catch:

 

 

using application = Autodesk.AutoCAD.ApplicationServices.Application;
public void Initialize()
{
    try
    {
        application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInitializing...");
        // Init stuff
        application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInitializing completed.");
    }
    catch (System.Exception e)
    {
        application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\Error while initializing app: " + e.Message);
    }
}

 

 

Regarding Windows marking the dll as unsafe, I don't know how to unlock it. Its file properties dialog won't display the "unlock" checkbox.

PS: When compililng the dll on the target machine, it successfully loads and works in Autocad.

0 Likes
Message 5 of 9

Kari.Heinola
Explorer
Explorer

I have seen this when required DLLs, like in my case NLog.dll, were not copied to the target computer.

0 Likes
Message 6 of 9

Ed__Jobe
Mentor
Mentor

You may not be seeing any error message written to the command line if a document is not active. Try putting the error trap in the OnIdle event, like below.


using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;

// This line is not mandatory, but improves loading performances
[assembly: ExtensionApplication(typeof(EJ_.MyPlugin))]

namespace EJ_
{
    public class MyPlugin : IExtensionApplication
    {

        void IExtensionApplication.Initialize()
        {
            AcAp.Idle += OnIdle;
        }

        void IExtensionApplication.Terminate()
        {
            // Do plug-in application clean up here
        }
        private void OnIdle(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
            {
                Application.Idle -= OnIdle;
                try
                {
                    doc.Editor.WriteMessage("\nEJ_PageSetupImport loaded.\n");
                }
                catch (System.Exception ex)
                {
                    doc.Editor.WriteMessage($"\nInitilization error: {ex.Message}");
                    doc.Editor.WriteMessage($"\nStack Trace: {ex.StackTrace}");
                }                
            }
        }
    }
}

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 9

ActivistInvestor
Mentor
Mentor

Don't waste time adding Idle event handlers, because you can't use the NETLOAD command without an active document.

 

The exception can occur long before your Initialize() method runs, if it references a type from an assembly that can't be loaded. In that case, Initialize() will never be called, because the exception occurs when it is just-in-time compiled prior to calling it. It's that JIT process where types that are referenced from Initialize() are loaded, from whatever assemblies they're in, and if the correct version of one of those assemblies cannot be found/loaded, that's when the exception occurs. 

 

Add a line to display a message on the console in the Initialize() method to confirm it's being called.

 

If Initialize() not being called, the easiest way to diagnose this, is to add a handler to the AppDomain's FirstChanceException event in another assembly that's already loaded. In the handler for the FirstChanceException event, dump the exception stacktrace to the console. That must be done in another assembly that's already loaded when you try to load the problematic assembly.

 

Another way to identify issues with assembly binding failures is to use fuslogvw.exe:

 

Fusion Log Viewer

🔹Location: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX <version>\fuslogvw.exe
🔹How to use:

  1. Open a Command Prompt as Administrator.
  2. Run fuslogvw.exe.
  3. In the Fusion Log Viewer, enable logging (Settings → Log All Binds).
  4. Load your assembly (e.g., via NETLOAD in AutoCAD).
  5. Refresh fuslogvw.exe to see binding failures.
  6. Click on an entry to see details about why the assembly failed to load.
Message 8 of 9

jptallano
Enthusiast
Enthusiast

Sorry for the delay, I could not answer sooner.

Using ActivistInvestor suggestion with FirstChanceException, I could solve the problem, and it was all my fault, because of a stupid assumption I was making.

Actually, the problem was that Autocad's version on the system I was installing my plugin on was newer than Autocad's version on my development computer. I mistakenly thought retro-compatibility was ensured - given that the gap between versions was not too far.

But that leads to another question: Do I need to have as many source project versions (carrying the same code but with different AcCoreMgd.dll/AcDbMgd.dll references) as there are Autocad versions I want to support?

0 Likes
Message 9 of 9

ActivistInvestor
Mentor
Mentor
Accepted solution

You can compile your app to Target a given version of the net framework. And it should run on any version of AutoCAD that uses that same version of the framework. For example, for AutoCAD 2025 you would need to create a separate assembly then the one that you would need to load for AutoCAD 2024 because they use different versions of The NET Framework