Title: two different DLL with same namespace
Tags: c#;visual-studio-2010;.net-2.0
Question: I have two DLL files that have the same namespace but they have different methods and types.
How can I reference both DLLs in my project and use their methods and types?
By the way, these two DLLs have some methods and types with the same name but different implementation and some unique methods and types.
Comment: The first question that comes to my mind is why are you creating 2 different dll for same namespace?

Comment: I'm not creating it. I am writing a program that should use 2 DLL which I can not change them becuase they are stable in their companies. unfortunately they both have a same file name and same namespace.

Comment: by the way. these two DLL have some functions and types with same name and different implementation and some unique functions and types.

Comment: He could just be trying to use two that happened to use the same namespace.

Comment: @Searock - it is quite common to find the same namespace spanning multiple assemblies, even within the framework and especially when using third party controls.

Here is the accepted answer: There's nothing special you need to do - just reference them and use the types. Namespaces can span accross several assemblies without problems, because they're not really opaque types. A namespace is just a way of adding a common prefix to all the types it contains, allowing you to have multiple types of the same name under different namespaces. (The framework doesn't see them as having the same names, because it sees the "fully qualified" name of everything - which has an alias and a namespace attached to the front of it.)
In the rare event that you reference 2 assemblies which have the same type names and the same namespaces (such as 2 different versions of the same dll) - you can distinguish which assembly to use for a given type using an alias. The default alias for all references is global, but you can specify your own alias for any assembly when you reference it (using a compiler switch - or just use the properties box in Visual Studio) - and have an extern alias <name&gt; clause at the top of your code file where you use it - you would access the types from different assemblies with <name&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0MyNamespace.Type
Comment for this answer: You can read about `extern alias` here: http://msdn.microsoft.com/en-us/library/ms173212.aspx

Here is another answer: If you have 2 types with the exact same name (note that the name includes the namespace) but in different DLLs and you are interested in using both of them, then you can do this.
Short Answer
You have type Acme.Foo in 2 different DLLs and you want to use them. Give the reference an alias in the reference properties window (View | Properties Window) then use it like this:
extern alias TheAliasYouGaveTheReference
TheAliasYouGaveTheReferen75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Acme.Foo f = new
TheAliasYouGaveTheReferen75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Acme.Foo();
The default namespace is global for any C# program but note above we are using the alias we created instead of global.
The best approach is to NOT get into a situation like this in the first place, if both assemblies are your own, then do not create 2 types with the exact same name in the exact same namespace. But sometimes we do not control the source code so for those times, the above solution can be used.
Long Answer
I am copying most of the article from here so it is recorded here in case the article is no longer available.
How do you get into a situation like this?
Firstly, here is how you can replicate the scenario so it is really clear what we are talking about:
Create a C# Class Library called FooVersion1
Replace the template code in Class1.cs with the following:
using System;
namespace Acme
public class Foo
public void Bar()
{
Console.WriteLine("Bar");
}
Right-click on the solution in solution explorer and select Add | New Project
Save the current project (only applicable in express)
Select a Class Library in the new project dialog and change the project name to FooVersion2 and press OK
Replace the code in Class1.cs with the following:
using System;
namespace Acme
public class Foo
public void Bar()
{
Console.WriteLine("Bar");
}
public void Goo()
{
Console.WriteLine("Goo");
}
Usage of the type in Application
Ok so now we have 2 different assemblies containing Acme.Foo. Let's now create a console application and try to use each one.
Right-click on the solution in solution explorer and select Add | New Project
Select a Console Application and call it Consumer
Right-click on Consumer and select ‘Set as startup project’
Right-click on the references node in the Consumer project and select ‘Add Reference’
Click on the projects tab, and multi-select FooVersion1 and FooVersion2
Click OK
Add the following line to Main in the Program type of the Consumer project:
Acme.Foo f = new Acme.Foo();
Build the solution via Ctrl+Shift+B (or F6)
Notice that you get two build errors [as shown below]:
The Fix
Here is how we can fix it:
Open solution explorer and select FooVersion1 in the References folder of the Consumer project
Hit F4 (or select View | Properties Window)
Change the Aliases property to FooVersion1
Build the solution
Now everything will build correctly, because Acme.Foo unambiguously refers to FooVersion2
Add the following directive to the top of Program.cs in the Consumer project:
extern alias FooVersion1;
Change the usage of Acme.Foo to:
FooVersion75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Acme.Foo f = new FooVersion75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Acme.Foo();
f.Bar();
Notice that when you type ‘f.’ the completion list contains only those methods in FooVersion1 of Acme.Foo (notably it does not include Goo)
Build the solution and everything will build correctly
Finally add the following code under f.Bar() in Program.cs of the Consumer project:
Acme.Foo f2 = new Acme.Foo();
f2.Goo();
Notice that f2’s completion list contains Goo.
Build again using Ctrl+Shift+B and notice that there are still no build errors
Comment for this answer: How I do it in vs code? I am really upset that most of the answers is always VS =(

Here is another answer: you can use the alias feature of the /reference (Import Metadata) (C# Compiler Options) compiler option to solve your problems,  read from here for more details

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2010:00:09/09/10', 'FavoriteCount': 12.0, 'PostTypeId': 1, 'Tags': '<c#><visual-studio-2010><.net-2.0>', 'Title': 'two different DLL with same namespace', 'ViewCount': 68525, 'id': 3672920, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}