An unusual sticky situation it is!
You have a external class, say Class Saviour , in your project. Class Saviour uses another class, Class MostSoughtAfter from codeplex. Class Saviour has implemented Class MostSoughtAfter to suit its needs. So where ever you create an instance of Class MostSoughtAfter, it will refer the Class MostSoughtAfter defined by Class Saviour . Suppose you need to use a function in the original Class MostSoughtAfter, and you add the dll . Visual Studio will throw a warning saying there is an ambiguity and that Class MostSoughtAfter implemented in Class Saviour is used to instantiate.
Bingo! You have multiple versions of the same class in your project and you need to reference them separately. I found a similar question in StackOverflow
Now in C# we have an “extern alias” keyword which will allow us to do the same. MSDN says
By using an external assembly alias, the namespaces from each assembly can be wrapped inside root-level namespaces named by the alias, which enables them to be used in the same file.
- In the solution explorer of your project, click the properties of the dll you want to reference,
- The Aliases field is set to ‘global’ by default. Change the global to name of your choice, say MyDLL.
- In the class you want to use the dll, first declare the alias right above the using statements
extern alias MyDLL;
- To use a method in the assembly we make use of :: qualifier
- Thus a simple creation of an instance of MyClass will use the class implemented in the project. And if you want to use the original dll reference using the alias .
‘extern’ and an MSDN blog saves my day!!
Happy coding !! 😀