Two or more different assemblies can contain a type with a same name and same namespace.
What will happen if you reference those assemblies in your project?
Well, referencing won’t result into any error. 🙂
How about making an object of that class?
This will fail. Compilation error will be generated because of ambiguity. Which type from which assembly should be used?
Compiler can’t make this decision on it’s own and rather i would say, it should not.
This should be done by a programmer/coder to clear his intentions to the compiler.
Let’s say, we have two assemblies:
Both assemblies define a type, say class having fully qualified name as SomeNameSpace.SomeClassName
We have a project where we refer the above two assemblies.
In order to instantiate an object of ProjectLibrary.Class defined in Assembly1, do:
- Change the Aliases property of one of the references
- Write a code statement on the top of your file: extern alias Assembly1;
- Lastly, change the object instantiation statement to
Assembly1::ProjectLibrary.Class obj = new Assembly1::ProjectLibrary.Class();
Whenever any reference is added, Aliases is set to global. Change this to your desired name, say Assembly1
Though this can be done for both but doing it for one will automatically open doors for another assembly.