views:

53

answers:

2

I have 2 different assemblies with the same name I need to add to my project.

When I try to add both references to the project, visual studio tells me the assembly is already referenced (because there is already an assembly with the same name).

I tried renaming one of the files. I could add both references but then, when accessing methods from the renamed assembly, resolving it fails (because .net tries to load the assembly with the original name).

Note: The assemblies are not mine, therefore I cant change their contents.

+2  A: 

If they are strongly signed and have different public keys maybe you can try this:

Have a separate library project for wrapping one of the two assemblies. That way you can choose a different name and namespace for one of them and then reference one of the two assemblies directly and the other indirectly.

The challenge will be that if both assemblies have the same file name you cannot have them in the same folder during runtime. As they are strongly signed you can put them both into the Global Assembly Cache (GAC) or you can put one of the two in a subfolder during runtime and add that subfolder to the probing path.

Good luck!

John
Creating a wrapping project seems like the best option, but then what is the best way to expose the inner assembly without having to write a stub for all classes, methods and properties?
Francisco Silva
In that case I would go for wrapping the one from which I need fewer classes, methods and properties.
John
A: 

Another option is to use ildasm to disassemble one of the assemblies and then use ilasm to assemble it back with a different name.

For example, to add 2 reference to the same assembly, on my system I do the following (windows 7, 64 bit, so adjust your paths accordingly)

d:\Sandbox>"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ildasm.exe" /all /out=SandboxLib2.il SandboxLib.dll

followed by

d:\Sandbox>"c:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe" /dll SandboxLib2.il

After this I have another assembly called SandboxLib2.dll. Even though its the same assembly as first, I can add references to both the .dlls in my project.

Chaitanya
Unless I did something wrong, this doesn't do it. The assembly will still have the original name which means that in practice I only seem to have the filename but not the actual assembly name.
Francisco Silva
Try updating the IL before recompiling. Open it in nodepad and do a text replace of all instances of SandboxLib with SandboxLib2. In the assembly section you will have to do some hex coding.
Chaitanya