Type exists in 2 assemblies

I know this is old, but there’s an easier way than the listed. This works when you reference two assemblies that share types with the exact same name and namespace.

If you right-click on the Reference to your DLL and select Properties, you will see that here’s a property called “Aliases”

enter image description here

The default value is “global”. For one of the conflicting assemblies change this to any other value. In the example below, I’ve changed it from “global” to “destination”.

Next, in your code file, you will have to use the extern keyword to use this alias as the root-level namespace for these types. In this example, you would place the following at the top of your .cs file:

extern alias destination

Now, within this file, you can reference both types.

extern alias destination;
namespace Test
{
    public static class TestClass
    {
        public static void Success()
        {
            var foo = destination::Some.Duplicate.Namespace.SomeDuplicateType();
            var bar = Some.Duplicate.Namespace.SomeDuplicateType();
        }
    }
}

Leave a Comment