arkina
arkina

Reputation: 1029

Can I reference two versions of a dll in the same project without putting them in the GAC?

Can I reference two versions of a dll in the same project without putting them in the GAC?

Thanks

Upvotes: 6

Views: 7761

Answers (3)

Hans Passant
Hans Passant

Reputation: 942109

You've got two problems. First one is getting your app to compile. You've got two assembly references that contain types with the same namespace name and type name, the compiler won't know which one to choose. You solve that by using "extern alias", it lets you rename the namespace of one of the assemblies. Review this question for further help.

The second problem is the one you ask about. Without the GAC, you need to help the CLR finding the correct DLL. You must put the DLLs in a separate directory, say a subdirectory of your build directory, so that the CLR cannot find them. Use a post build event to create this directory and copy the DLLs into them. Give them distinct names.

Then implement the AppDomain.CurrentDomain.AssemblyResolve event. The CLR will fire it when it cannot find the DLLs you've hidden. Use Assembly.LoadFrom() to load and return the assembly it asks for. The e.Name property has the full assembly name, use the AssemblyName class to parse that string and retrieve the Version property.

Upvotes: 7

Mohammad Nadeem
Mohammad Nadeem

Reputation: 9392

Referring to an assembly without putting it into GAC means copying the dll in the bin folder of the project. And you cannot have two dlls of same name in the bin folder.

Upvotes: 0

Anuraj
Anuraj

Reputation: 19608

You cannot put reference of the same assembly twice.

Upvotes: -3

Related Questions