Class with same name in two assemblies (intentionally)

You can use an extern alias to reference types with the same fully qualified name from different assemblies. Select the reference to LibraryCS and update Aliases in the properties page from "global" to "LibraryCS", and add extern alias LibraryCS; to the top of your source file, and then you can use LibraryCS::MyNamespace.MyClass to refer to the class in LibraryCS. You can use MyNamespace.MyClass or global::MyNamespace.MyClass to refer to the class in LibWrapper, or you can use an alias for that reference as well.


Saw this question and answer and it helped me. How ever for those who need a detailed explanation on the same, i found a link which is really useful.

Extract from the link.

Using different versions of the same dll in one application

step 1: using the VS IDE. Add the reference to both the dlls in your client application solution. Then in the Solution Explorer under the reference node select the first (old version) class library. In the property window change Aliases field from global to oldVer. lly, newVer for the Newer version.

Step 2: use the below code as the first statements where you plan to reference it

extern alias oldVer;
extern alias newVer;

now to use,

Console.WriteLine(oldVer::MyLibrary.MyClass.method());
Console.WriteLine(newVer::MyLibrary.MyClass.method());

Hope this helps.


In order to load both of these classes in the same executable, you could to load them in a separate Application Domain. This would let you test the assembly, then fully unload it and load the second one and test it.

For details on how to do this, see How to: Load Assemblies into an Application Domain and Unload an Application Domain.