CADmep 2021 - A procedure imported by 'FabricationAPI.dll' could not be loaded

JC_BL
Advocate

CADmep 2021 - A procedure imported by 'FabricationAPI.dll' could not be loaded

JC_BL
Advocate
Advocate

I keep getting the error message "System.IO.FileLoadException: A procedure imported by 'FabricationAPI.dll' could not be loaded." when I try to run the add-in that I have written in CADmep 2021.

 

The add-in runs fine in CADmep 2019 for many years.  I am trying to create a version for CADmep 2023.  It loads OK in CADmep 2023.  But it fails whenever it needs to get access to anything related to Fabrication API.  Because I am not making any headway with running my add-in in CADmep 2023, I want to try my luck with CADmep 2021.

 

Unfortunately the add-in behaves even worse in CADmep 2021.  In the IExtensionApplication.Initialize() of my add-in, I ask it to explicitly load the correct version of FabricationAPI.dll  -- that is the one in C:\Program Files\Autodesk\Fabrication 2021\CADmep folder.  But I immediately get the error "A procedure imported by 'FabricationAPI.dll' could not be loaded" when CADmep is starting up.  The following is the IExtensionApplication.Initialize() that tries to explicitly load FabricatonAPI.dll:

 

void IExtensionApplication.Initialize()
   {
   try
      {
      String sFullPathFabApiDllFileForCAD = "C:\\Program Files\\Autodesk\\Fabrication 2021\\CADmep\\FabricationAPI.dll";
         // Of course the folder name is changed for 2019/2021/2023.
      Assembly oAsm = System.Reflection.Assembly.LoadFrom( sFullPathFabApiDllFileForCAD );
      if ( oAsm == null )
         {
         MessageBox.Show( "Fail to load FabricationAPI.dll",
                          "MyAddin", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
         }
      }
   catch( System.Exception ex )
      {
      Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
      Editor   ed  = doc.Editor;
      ed.WriteMessage( "\n" + ex.Message );
      return;
      }
   finally
      {
      }
   }

 

And I notice that the commands exposed from my add-in are not available.  Use NETLOAD to manually load my add-in seemingly helps because the commands exposed from my add-in start showing up.  Unfortunately I encounter the same error when I try to run any command exposed from my add-in.  Seem like FabricationAPI.dll is not loaded.

 

I also try commenting out the code that tries to explicitly load FabricationAPI.dll, and let CADmep to implicitly load FabricationAPI.dll.  This avoids the error during starting up of CADmep.  And I also notice that the commands exposed from my add-in start showing up.  But I encounter the exact same error when I try to run any command exposed from my add-in.

 

I have tried Dependency-Walker to examine 2021 FabricationAPI.dll, and I see a long list of errors.  But I also see the same long list of errors when I examine 2019 FabricationAPI.dll (and my add-in works fine in 2019 Fabrication API).  Therefore, I don't know if those errors are relevant or not.

 

I have checked using Resource Monitor and found that FabricationAPI.dll indeed was not loaded with CADmep 2021.  Only FabricationCore.dll (2021 version) is loaded.

 

Would you please let me know what else that I should try?  Thanks.

 

JC_BL

0 Likes
Reply
288 Views
2 Replies
Replies (2)

JC_BL
Advocate
Advocate

So, my questions are:

 

Why CADmep 2021 cannot preload 2021 version of FabricationAPI.dll automatically?

 

Why my add-in cannot explicitly load any version of FabricationAPI.dll (2019/2021/2023) in CADmep 2021?

 

Please help.  Thanks.

 

JC_BL

0 Likes

JC_BL
Advocate
Advocate

The problem is fixed.  I mentioned the fix in another message thread called "How to Have Fabrication 2019 and Fabrication 2023 Co-Exist in the Same PC?" in this forum.

 

Despite the fact that I have fixed the problem, I don't know why the "fix" can prevent this problem from happening and why the problem happened in the first place.  Therefore, I cannot call this issue as fixed.  If someone knows why, please let me know.  Thanks.

 

JC_BL

0 Likes