#532 – Using Identically Named Types from Different Assemblies

If you want to use two types from different assemblies that have exactly the same name, including the namespace, your application won’t know which type to use.  The fully qualified type names are identical and you’ll get an error.

You can use both types in your project by providing an extern alias for the namespace hierarchy in one of the DLLs.

In Visual Studio, in your application, select the reference to one of the two assemblies.  Change the Aliases property from global to a new name.

Now include an extern alias statement in your code, using the same name.  Then use this alias to reference types in the aliased assembly.

using DogLibrary;   // FirstDogLibrary.dll

namespace ConsoleApplication1
    extern alias AnotherLib;

    class Program
        static void Main()
            // DogLibrary.Dog in FirstDogLibrary.dll
            Dog d = new Dog("Kirby", 12);

            // DogLibrary.Dog in AnotherDogLibrary.dll
            AnotherLib::DogLibrary.Dog d2 = new AnotherLib::DogLibrary.Dog("JRT", "Jack");

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #532 – Using Identically Named Types from Different Assemblies

  1. Pingback: #533 – Alternate Notation for Extern Aliases « 2,000 Things You Should Know About C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: