One shared dll for multiple AutoCAD plugins

One shared dll for multiple AutoCAD plugins

vucic_tamara
Enthusiast Enthusiast
994 Views
9 Replies
Message 1 of 10

One shared dll for multiple AutoCAD plugins

vucic_tamara
Enthusiast
Enthusiast

Hello all,

 

In my company we have few applications that relay on our internal dll that contains helper methods when working with AutoCAD. So the structure is as following:

 

popovictamara91_0-1693897966659.png

Because AutoCAD only loads one version of the shared dll, if one of the applications installed references the newer/later version of shared dll we have problem, because AutoCAD won't allow different versions of the same dll to be loaded. So what would be your approach/advice when dealing with these scenarios?

 

Greetings,

Tamara

 

 

0 Likes
995 Views
9 Replies
Replies (9)
Message 2 of 10

gleeuwdrent
Advocate
Advocate

I have solved this by creating an own DLL-loader. This is a dll which loads all dll files in a specific path and order using the Assembly.LoadFrom(filename); method.

Only the DLL-loader is loaded in the ApplicationPlugins - bundle folder. When this dll is loaded into AutoCAD, it start loading my project dll files. In my installation file I provide always the latest version of the shared dll's. This forces AutoCAD to always loads the latest version.

 

The only disadvantage of this method is that you cannot simply remove or change methods from the shared dll, because they could be used by old applications.

0 Likes
Message 3 of 10

Anton_Huizinga
Advocate
Advocate

You could use reflection to load a dll in runtime. I use that to run Civil 3D functions in an application that also needs to run in vanilla AutoCAD.

0 Likes
Message 4 of 10

Anton_Huizinga
Advocate
Advocate

Reconsidering your process, I think it is better to use a version in the reference ddl and namespace, for example, MyHelper0603.dll and main namespace MyNamespace0603. After an update it is easy to perform a search and replace, and each application will maintain the reference to the correct helper file.

0 Likes
Message 5 of 10

vucic_tamara
Enthusiast
Enthusiast

Thank you, something similar crossed my mind but than I also thought of the drawback you mentioned so I gave it up. But will reconsider perhaps.

0 Likes
Message 6 of 10

vucic_tamara
Enthusiast
Enthusiast

Thank you Anton, we also thought about this procedure but we hoped there is a more elegant way. So changing only the .dll name is not enough, namespaces also must be changed?

0 Likes
Message 7 of 10

Anton_Huizinga
Advocate
Advocate
I'm pretty sure. Once I used an Open Source Excel engine, but it was overruled by a newer version that was referenced in another plugin.

But to be sure, you could set up a small test.


Message 8 of 10

gleeuwdrent
Advocate
Advocate

If you set your referenced assembly property 'Specific version' on False, you don't need to use an specific version. You only have to make sure that your classes and methods you are using in your project are available at runtime. So if you add a method to your shared dll, you have to make sure that the latest version of your helper dll is available. And you cannot remove methods.

gleeuwdrent_0-1694152297360.png

 

Message 9 of 10

tarekahmed136
Contributor
Contributor

Did you find an elegant approach for these scenarios ?

0 Likes
Message 10 of 10

ActivistInvestor
Mentor
Mentor

I've used shared libraries often. I usually add a reference to them from projects that use them, where I set COPYLOCAL to false, and then deploy the shared dll in a known location that each project can reference. As far as different versions, if you mean the assembly version, I don't change it unless there is a breaking change, which is something I try to avoid at all costs.