RegAsm cannot find dependent library when registering a DLL

RegAsm cannot find dependent library when registering a DLL

Anonymous
Not applicable
10,395 Views
12 Replies
Message 1 of 13

RegAsm cannot find dependent library when registering a DLL

Anonymous
Not applicable

Trying to update an old VBA application - without rewriting the whole thing - which has a dependency on two libraries from AutoCAD Mechanical 2007 (GeAuto.dll and BrepAuto.dll).  I thought I would just write some COM visible .NET dlls and replace the calls to the original libraries with the .NET components that do the same work.  Probably not exactly that simple, but that is the idea.  Anyway, starting simple, I created my replacement for GeAuto  and put in a class called GePoint that will implement whatever methods I need, but use an encapsulated Autodesk.AutoCAD.Geometry.Point3d as a delegate for doing the actual work.  Now, when I run RegAsm.exe, I get an error message like below and I don't know what to do next.  I am including the command line in case I'm doing something wrong with that as well.  Curiously, while I get the error when using Point3d or Vector3d, I do NOT get it when using CompositeCurve2d.  I have tried setting CopyLocal to True for all of the referenced AutoCAD assemblies, but no change.

 

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /tlb:C:\UDir\0Dev\Projects2012\GEAuto\GEAuto\bin\Debug\\GEAuto.tlb C:\UDi
r\0Dev\Projects2012\GEAuto\GEAuto\bin\Debug\\GEAuto.dll
Microsoft .NET Framework Assembly Registration Utility version 4.0.30319.34209
for Microsoft .NET Framework version 4.0.30319.34209
Copyright (C) Microsoft Corporation. All rights reserved.

 

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed onthe same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
RegAsm : error RA0000 : Could not load file or assembly 'Acdbmgd, Version=20.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt
was made to load a program with an incorrect format.

0 Likes
Accepted solutions (1)
10,396 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

OK, I guess, unlike StackOverflow, this forum does NOT allow you to edit an existing post so I'll have to reply to myself to correct something in the original post.  Seems like an inefficient use of everybody's time...  The command line should have been as below - no double '\'s.  I just named my new dlls, the namespace, and the classes like they were in the original ACADM 2007 libraries because the VBA IDE doesn't have as nice a facility for renaming variables and types, or reporting errors as VS2012.

 

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /tlb:.\GEAuto.tlb .\GEAuto.dll

0 Likes
Message 3 of 13

dgorsman
Consultant
Consultant

@Anonymous - you can edit your own post, provided you do it within 30 minutes or someone else hasn't replied.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 13

Anonymous
Not applicable

I don't see any means of editing an existing post.  You'd think maybe an 'edit' button, link, or menu item somewhere?

0 Likes
Message 5 of 13

ActivistInvestor
Mentor
Mentor
Accepted solution

@Anonymous wrote:

OK, I guess, unlike StackOverflow, this forum does NOT allow you to edit an existing post so I'll have to reply to myself to correct something in the original post.  Seems like an inefficient use of everybody's time...  The command line should have been as below - no double '\'s.  I just named my new dlls, the namespace, and the classes like they were in the original ACADM 2007 libraries because the VBA IDE doesn't have as nice a facility for renaming variables and types, or reporting errors as VS2012.

 

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /tlb:.\GEAuto.tlb .\GEAuto.dll


The reason you're having the problem is because your assembly is dependent on AcDbMgd.dll, which cannot be loaded into any process other than AutoCAD.

 

One way to overcome the problem is to load your assembly into into AutoCAD via the NETLOAD command, and then do the registration via code.  

 

You can use the System.Runtime.InteropServices.RegistrationServices class to do that.

 

Regarding editing messages, you can do that up to 30 minutes after you've posted, but not afterwards.

0 Likes
Message 6 of 13

Anonymous
Not applicable

That explanation fails to explain why the reference to CompositeCurve2d - which is defined in acdbmgd - does NOT cause any problem like the point and vector are causing.  I will try to post a testable code sample later.

 

As for editing my own post - I can now see the drop down menu item for this immediately after I make the post.

0 Likes
Message 7 of 13

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

That explanation fails to explain why the reference to CompositeCurve2d - which is defined in acdbmgd - does NOT cause any problem like the point and vector are causing.  I will try to post a testable code sample later.

 


The cause or reason why the code doesn't fail with CompositeCurve2d is irrelevant to the problem.

 

The problem occurs because acdbmgd.dll cannot be loaded into any process other than AutoCAD.  

 

If you really insist on being pedantic, the reason why the failure occurs with Point3d and Vector3d, is because they are structs that perform static, module-level initialization, whereas CompositeCurve2d is not a struct and has no module-level initialization code. It is the static initialization done by Point3d and Vector3d that triggers the loading of acdbmgd.dll. If you had module-level static initialization code (not possible in a pure managed assembly that is not unsafe) that tried to instantiate an instance of CompositeCurve2d or any other class type from acdbmgd.dll, the failure would also occur during loading.

 

Save yourself the time/effort of posting a test sample, because there is no purpose to it.

 

 

0 Likes
Message 8 of 13

Anonymous
Not applicable

That's actually really good information and an important point.  I have never worked with the struct in C# - believing them to be the same as in ANSI C and just a grouped set of variable values.  Taking new note of how many structs are actually used in the AutoCAD object universe, I am going to pay closer attention to that in the future so I don't make the mistake of working with a value type in the way I would with a reference type. But you're correct, it's not going to help me with the current problem.

 

Now, for the real problem, I'm no longer sure registration is the root of it.  As you say, if the acdbmgd.dll can only be loaded into AutoCAD, and I'm trying to create a COM-visible dll for VBA, my assembly would not get loaded into AutoCAD in the usual 'netload' way.  So maybe I'm not even going to be able to do what I thought I'd be able to do?

 

I actually need to work with both Autodesk.AutoCAD.BoundaryRepresentation as  well as Autodesk.AutoCAD.Geometry.  I just started with Geometry figuring more people would be familiar with it.  I guess I need to post a different question that directly addresses what I'm trying to do.

 

 

 

0 Likes
Message 9 of 13

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

 

 

Now, for the real problem, I'm no longer sure registration is the root of it.  As you say, if the acdbmgd.dll can only be loaded into AutoCAD, and I'm trying to create a COM-visible dll for VBA, my assembly would not get loaded into AutoCAD in the usual 'netload' way.  So maybe I'm not even going to be able to do what I thought I'd be able to do?

 

 


Your assembly must be loaded into AutoCAD's process space. That is done by having the ActiveX client obtain the server using the AcadApplication.GetInterfaceObject() method. This is like GetObject() except that the COM server is loaded into AutoCAD's process rather than the client's process.

0 Likes
Message 10 of 13

Anonymous
Not applicable

So, let me make sure I am clear on the order of events that need to happen:

 

1) Develop my .NET dll to replace GeAuto.dll

2) Do a one-time netload of the dll and run a command defined therein to register the assembly for COM (MyLib.GeAuto)

3) Thereafter, I will not need to netload the dll

4) Instead my VBA code will call something like

  Dim MyGeAuto as MyLib.GeAuto

  Set MyGeAuto = AcadApplication.GetInterfaceObject(MyLib.GeAuto)

 

Does that sound about right?

 

>>Your assembly must be loaded into AutoCAD's process space. That is done by having the ActiveX client obtain the server using the AcadApplication.GetInterfaceObject() method. This is like GetObject() except that the COM server is loaded into AutoCAD's process rather than the client's process.

0 Likes
Message 11 of 13

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

So, let me make sure I am clear on the order of events that need to happen:

 

1) Develop my .NET dll to replace GeAuto.dll

2) Do a one-time netload of the dll and run a command defined therein to register the assembly for COM (MyLib.GeAuto)

3) Thereafter, I will not need to netload the dll

4) Instead my VBA code will call something like

  Dim MyGeAuto as MyLib.GeAuto

  Set MyGeAuto = AcadApplication.GetInterfaceObject(MyLib.GeAuto)

 

Does that sound about right?

 

 


 

Yes, except that you don't need to define a command to register the DLL, you can just do it in the IExtensionApplication.Initialize() method, which is called when the assembly is NETLOADed. 

0 Likes
Message 12 of 13

Anonymous
Not applicable

The problem with using the Initialize method is that the registration requires elevated permissions.  So, in order for it to succeed, AutoCAD needs the Run as administrator treatment on launch.  Better to use a separate registration method so AutoCAD can be run as administrator, the command to register the dll executed, and thereafter it can be run normally and the library used from VBA without firing the Initialize method upon GetInterfaceObject.

0 Likes
Message 13 of 13

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

The problem with using the Initialize method is that the registration requires elevated permissions.  So, in order for it to succeed, AutoCAD needs the Run as administrator treatment on launch.  Better to use a separate registration method so AutoCAD can be run as administrator, the command to register the dll executed, and thereafter it can be run normally and the library used from VBA without firing the Initialize method upon GetInterfaceObject.


The idea was to use NETLOAD to register the assembly, not GetInterfaceObject().  If the IExtensionApplication.Initialize() method is running when you call GetInterfaceObject(), you can look at the active command in the editor, and see if it is NETLOAD, and do the registration only in that case.

 

That way, you don't need to use a command, you just have to NETLOAD the assembly to register it. If you want to provide a means of un-registering the assembly, then you will need a command for that.

0 Likes