.NET

Reply
Distinguished Contributor
jmaeding
Posts: 932
Registered: ‎12-27-2006
Message 1 of 22 (646 Views)
Accepted Solution

.net helper dll's of same name, which one used?

646 Views, 21 Replies
12-09-2013 02:46 PM

I was always under the impression you could make two .net programs for acad, say called prog1 and prog2, and place supporting dll's in each of the folders.

So Prog1's folder would have "helpers.dll", as well as Prog2's folder.

Like:

  Prog1

    Helpers.dll

  Prog2

    Helpers.dll

 

Now, each prog should look to its helpers.dll, as these are not going into the GAC.

 

What I am seeing though, is my Prog2 is using the Prog1's helper.dll during debug in acad.

Note that Prog1 gets neloaded on startup, so its loaded first.

 

I had not noticed this before as I kept helpers.dll in synch. I then allowed Prog2's to get ahead, by adding a method, and noticed I got a "method missing" error at runtime in acad.

Its like VS said everything was ok, but acad somehow said "no, use this helpers.dll for the .net prog already loaded".

 

I am not netloading the helpers.dll, it just sits there as support.

Any ideas how this crosstalk could happen?

 

The implication is I would not be able to have duplicate supporting dll's for various progs I do.

That is wrong though, .net does allow dupe named dll's so long as they sit right next to the calling dll.

thx

 

 

 

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 2 of 22 (611 Views)

Re: .net helper dll's of same name, which one used?

12-10-2013 10:01 AM in reply to: jmaeding

Your issue is that you expect the different DLLs with the same file name, the same version, and the same namespace, but broken compatibility (e.g. all the information in the AssemblyInfo.vb[cs] are the same) to be loaded into the same process (AutoCAD running process).

 

Your DLL is dynamically loaded when needed, Then the running process (AutoCAD) sees the need to use functionalities in a DLL, it would examine the meta data of loaded assemblies, if it has already been loaded, it will not try to load it from file again. If not loaded, it will try to loaded by looking into GAC/App folder... the usual probing.

 

So, that is why Helps.dll has already been loaded because of Prog1, then when Prog2 is loaded and needs Helps.dll, AutoCAD simply uses the loaded Helps.dll, and not tries to load Helpds.dll again from Prog2 folder.

 

The probelems is when do you deliberately create a DLL with the same filer name (and probably the same version, namespace...) yet make different interface (properties, methods) in it? At least you need to make different versions (.NET allows the same components with different version being loaded side by side), if you have to keep the DLL name, namespace the same for some reasons.

 

 

 

Distinguished Contributor
jmaeding
Posts: 932
Registered: ‎12-27-2006
Message 3 of 22 (604 Views)

Re: .net helper dll's of same name, which one used?

12-10-2013 10:28 AM in reply to: norman.yuan

I see, very well explained.

Things like versions have never mattered to me since I generally recompile all programs if my central library changes.

Its always "the latest" :smileyhappy:

 

I will try that right now. Dealing with making sure no other .net progs of mine were loaded into the debug session was not easy (or fun)....

thanks a bunch!

Board Manager
StephenPreston
Posts: 362
Registered: ‎05-22-2006
Message 4 of 22 (596 Views)

Re: .net helper dll's of same name, which one used?

12-10-2013 12:17 PM in reply to: jmaeding

Nicely explained Norman. Kudos to you.

 

James - I suggest you mark that as your accepted solution.

 

Cheers,

Stephen Preston
Autodesk Developer Network
Distinguished Contributor
jmaeding
Posts: 932
Registered: ‎12-27-2006
Message 5 of 22 (581 Views)

Re: .net helper dll's of same name, which one used?

12-11-2013 03:30 PM in reply to: StephenPreston

I was going to mark it as solution, and think it is the right answer, but its not working.

I opened the solution for prog1, and edited all the Assemblyinfo.cs files to have:

[assembly: AssemblyVersion("1.0.*")]

//[assembly: AssemblyFileVersion("1.0.0.0")]

 

I commented the file version so it would use the AssyVersion, and I could see in props of file in windows explorer.

 

I purposefully commented out a particular method I know prog 2 needed before I compiled.

I then compiled, and placed the new files in my regular prog1 folder which is where acad finds them.

It seemed to assign the version info as expected. I verified in explorer.

 

I then uncommented the method and ran prog2 under debug, and got the method missing error.

I looked at the details to see what dlls were loaded, and it only lists the one from Prog1.

See Pic of one acad listed, and details of one from prog2 folder. The versions are different, but acad never loaded the one from prog2.

Asm Vers.jpg

 

 

That HAH General CS.dll is the helper function that is different between prog1 and prog2.

Did I misunderstand something? I thought the different versioning would make acad load both and use the one prog2 is calling for.

thanks

 

Distinguished Contributor
jmaeding
Posts: 932
Registered: ‎12-27-2006
Message 6 of 22 (580 Views)

Re: .net helper dll's of same name, which one used?

12-11-2013 03:33 PM in reply to: jmaeding

just thought of something. Does acad maybe only look at major version (3rd number) of an assy to decide if its the right one?

Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 7 of 22 (561 Views)

Re: .net helper dll's of same name, which one used?

12-11-2013 11:54 PM in reply to: jmaeding

The attributes window explorer show are just for public information Product, File, version etc....

 

The one that matters is AssemblyVersion but unfortunately AutoCAD does not allow strongly named assemblies which is required for the CLR to look at the AssemblVersion.

 

I have no idea if this would in this situation but if you want reference the assembly of different versions in the same project..

 

Select reference then in the Properties palette change alias from global to oldversion or whatever 

Then in code file  instead of a using directive use

extern alias oldversion;

 I have no idea if it will work in this situation but that is one way to load multiple versions of same assembly from different locations into same project.

 

 

 

You can also find your answers @ TheSwamp
*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 8 of 22 (545 Views)

Re: .net helper dll's of same name, which one used?

12-12-2013 06:52 AM in reply to: jmaeding

In my previous reply, I mentioned versioning. At the time I just vaguely recall .NET allows different versions of a component lives side by side from my early experience with .NET and had not touched this topics for years. Then I went to a bit study and test last night and here what I can say:

 

If you want to load the same component with the same assembly file name, namespaces..., but different version, into the same running process (AutoCAD, or other), the assembly has top be strongly signed and installed into GAC.

 

I did a test as following:

 

1. create 2 class library projects that has the same output DLL file name, the same namespaces, only differ with their assembly versions (1.0.0.0, and 1.1.0.0). Both projects have a static method doing different things: Add() and Substract().

 

2. Strongly signed the 2 projects and compile them;

 

3. Add the 2 DLLs (the file names are the same: "myLib.dll") to GAC with gacutil.exe tool;

 

4. Create a 2 Acad Addin projects. One of them references to myLib.dll v1.0.0, the other references to MyLib.dll 1.1.0. Note, I needed to point the reference to correct MyLib.dll file, because the MyLib.dll added into GAC does nt show up in "references" dislog box (unless I update the windows registry, which I do not bother). "Copy local" to MyLib.dll should be set to False, but even leaving it to True does not do hurt, because 2 versions of MyLib.dll in the GAC, and any app using them will always try to load them from GAC first anyway.

 

5. One Acad Addin has a command method ("Test1") that calls Add() in MyLib.dll v1.0.0, the other Acad addin has a command method ("Test2") that calls Substract() in MyLib.dll v1.1.0. Compile each projecys.

 

6. Start AutoCAD, net load AcadAddin1 and then netload AcadAddin2. execute command "Test1" and Test2". both work as expected: one does the adding and the other does the substracting, obviously from the 2 MyLib.dll versions being loaded into the same AutoCAD process.

 

Of couse I tried to load the 2 version of MyLib.dll into AutoCAD before strongly signed them and adding them to GAC. It did not work.

 

If we think it through, it make sense for not strongly signed DLL, the file name determines whether the assembly has been loaded or not, because it is physically stored in file system and can be overwitten by the any file with the same file name, regardless its version, content. While GAC is a special storage for .NET assembly that allows different versions of assembly stay side by side (but must be strongly signed).

 

So, if you really have to use the same assembly file name with different versions for particular reason, you have to strongly sign them and place them into GAC. which requires admin priviledge to get it done on each computer that may use your application. It may not worth the trouble doing it.

Distinguished Contributor
jmaeding
Posts: 932
Registered: ‎12-27-2006
Message 9 of 22 (540 Views)

Re: .net helper dll's of same name, which one used?

12-12-2013 08:37 AM in reply to: norman.yuan

wow, I think the whole ADN team should give you kudos on that research.

I would guess experienced .net people know you must use the GAC, but its not mentioned much in this forum.

Very much appreciated.

 

You are correct that I do not want to have to "install" my prog1 and 2 with admin.

I support about 60 cad users and update their tools via xcopy methods (robocopy.exe actually).

So I will have to figure out how I do things.

I will likely recompile both progs should I make any library changes.

If I am doing that, I might as well throw both progs in same folder too, no point in keeping separate.

 

I sure wish really really badly there was a way to do the GAC stuff via script, even if it meant exposing my login password.

I do not have security problems, I have timing problems.

I need to be able to tell users via an email to close acad's when convenient, then run some batch to update their tools.

As is, for admin requiring items, I have to have them close acad's, then run a special script through our remote admin prog from my desk. It interrupts what I am doing.

So solving that would pave the way for using GAC, I know its the right way to do it really.

thx

 

Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 10 of 22 (498 Views)

Re: .net helper dll's of same name, which one used?

12-13-2013 08:13 AM in reply to: jmaeding

Public deploy - GAC(Shared among different applications)

Privatley deployed - Placed in directory or sub-directory of application.

 

It just has to be Strongly named for the CLR to lokk at version number.

You can add Probing paths, Redirective bindings, etc.. inside app.config file(acad.exe.config)-Privately deployed.

 

You can avoid the GAC but would have to be strongly named and inside of autocad installtion folder.

 

 

This might be more of a project structure-maintenece problem instead of trying to load 2 different versions.

 

 

You can also find your answers @ TheSwamp

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community