Can not load dll to audocad

Can not load dll to audocad

tothapal
Participant Participant
621 Views
4 Replies
Message 1 of 5

Can not load dll to audocad

tothapal
Participant
Participant

I have a dll with multiple commands and we are using it with Civil 3d 2021 perfectly in the last few years. I developed a new command which isn't using any civil objects (only autocad objects) and it is working perfectly in civil. However, if I try to load my dll to autocad 2021 nothing happens, no error message and the commands are not there. I tried to run it in debug mod and added a breakpoint in the first row in the initialize method, but never stops.   

I have created a new dll to try, added the same resources, same nugets, changed the settings to be the same (same .net framework...) and even added civil objects to the code and it is working properly in autocad, but my orignial dll not.

 

Is there a way to solve this problem? If I would get an error message, the would be already a help...

 

0 Likes
622 Views
4 Replies
Replies (4)
Message 2 of 5

ActivistInvestor
Mentor
Mentor

AutoCAD suppresses exceptions that are thrown from the IExtensionApplication.Initialize() method. Most-likely the cause is something in your initialization code that may be referencing a type from the Civil3d assemblies.

 

The following code shows how I avoid the problem of AutoCAD suppressing or concealing exceptions in an IExtensionApplication's Initialize() method:

 

/// <summary>
/// Abstract base type for ExtensionApplications, that defers
/// Initialization until the first idle event when there is an
/// open document.
///
/// This class will also report exceptions thrown by an
/// override of the Intialize() method on the command line,
/// which solves the problem of AutoCAD's managed runtime
/// suppressing or concealing exceptions thrown from the
/// IExtensionApplication.Initlialize() method.
///
/// Usage:
///
/// This class should not be altered. Just include it in 
/// a project and derive a new class from this class, and 
/// implement/override the Initialize() method to do one-time 
/// initialization at startup, and optionally, override the 
/// Terminate() method to do finalization tasks at shutdown.
/// 
/// </summary>

public abstract class ExtensionApplicationAsync : IExtensionApplication
{
   void IExtensionApplication.Initialize()
   {
      this.Initialize();
   }

   protected abstract void Initialize();
   protected virtual void Terminate()
   {
   }

   void OnIdle(object sender, EventArgs e)
   {
      if(Application.DocumentManager.MdiActiveDocument != null)
      {
         Application.Idle -= OnIdle;
         try
         {
            this.Initialize();
         }
         catch(System.Exception ex)
         {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
               ex.ToString());
         }
      }
   }

   void IExtensionApplication.Terminate()
   {
      this.Terminate();
   }
}

/// <summary>
/// Example use of ExtensionApplicationAsync.
/// None of the code above needs to be altered.
/// Instead, you just derive your class from it.
/// </summary>

public class MyApplication : ExtensionApplicationAsync
{
   protected override void Initialize()
   {
      /// TODO: Initialize your application here
   }

   protected override void Terminate()
   {
       /// TODO: Finalize your application here
   }
}

 

 

 

 

0 Likes
Message 3 of 5

tothapal
Participant
Participant

Thank you for your message!

 

I tried your approach, but still the same problem. I even commented out everything in my Initialize method, but still nothing happened...

0 Likes
Message 4 of 5

ActivistInvestor
Mentor
Mentor

That means the problem is not in your Initialize() method, it is happening before AutoCAD calls the Initialize() method. That's usually an indication that it can't load a dependent assembly. So, you'll have to try to identify what dependent assembly is causing the problem and remove the dependency.

 

You might want to enable fusion logging to find out more about what's happening.

0 Likes
Message 5 of 5

tothapal
Participant
Participant

Thank you again your reply. I tried to use the Fusion log viewer, but I didn't get any log message while I loaded the dll. 

0 Likes