Sunday, January 22, 2006 10:53 PM
Chris
New Feature for VS 2005
Have you ever set references to two different assemblies and discovered that you have a name collision on a class that you are trying to use? What's worse, although the samed named class is defined in two different assemblies there is also a name collision on the namespace and you don't have access to the source for either assembly.
Given this situation with the 1.0 or 1.1 framework you really didnt have many choices. Your only choice was to create a layer on top of one of the classes. Although I don't really expect this to happen very often, in VS 2005 there is a feature called "external aliases" that will permit you to handle this situation should it ever arise.
For example:
//Foo.dll
namespace Stuff
{
public class Utils
{
public static void F() {...}
}
}
//Bar.dll
namespace Stuff
{
public class Utils
{
public static void F() {...}
}
}
//When used you refer to the external alias. This will permit you to use both versions of "Stuff".
extern alias Foo;
extern alias Bar;
class Program
{
static void Main() {
Foo.Stuff.Utils.F();
Bar.Stuff.Utils.F();
}
}
In order for this to work, you must assign an external alias at compile time. The /r switch is used.
For example, if compiling from the command line you would enter:
C:\>csc /r:Foo=foo.dll /r:Bar=bar.dll test.cs
and
C:\>csc /r:Foo=foo.dll /r:Foo=Foo.dll test.cs
As I mention, this is a feature that I expect to mostly go unused, but, it is nice to know that it exists.