Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace class conflict

Tags:

namespaces

c#

First of all, I know that this is because of bad libraries, but I don't have code for them to fix this.

XXX.dll contains class Util in global namespace. Util.dll has namespace Util.

When I include both .dlls I can't use Util namespace (Error 1 The namespace 'Util' in '..\Util.dll' conflicts with the type 'Util' in '\XXX.dll').

Because both are in global namespace I don't see how aliasing can fix this.

What is best solution for this? For now i know that I can make another .proj which will not include both .dlls and wrap classes I need. But this is not easily done ;(

like image 764
watbywbarif Avatar asked Jan 04 '12 09:01

watbywbarif


People also ask

How to resolve namespace conflict c#?

You need to use the global keyword. That forces the namespace resolution to start at the very top. It's mostly used in generated code to be doubly sure the right namespace is referenced. As an aside, it's probably best to avoid using System as a name of namespace.

What is the namespace of a class?

Classes are data types. They are an expanded concept of structures, they can contain data members, but they can also contain functions as members whereas a namespace is simply an abstract way of grouping items together. A namespace cannot be created as an object; think of it more as a naming convention.

Can namespace and class have same name?

Two classes with the same name can be created inside 2 different namespaces in a single program. Inside a namespace, no two classes can have the same name. In C#, the full name of the class starts from its namespace name followed by dot(.)

Why do we use namespace in asp net?

The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.


4 Answers

You should be able to use extern aliases for this - they allow you to effectively qualify a reference with which assembly you mean. Anson Horton has a good walkthrough for them.

like image 124
Jon Skeet Avatar answered Oct 17 '22 05:10

Jon Skeet


Yes, there is a solution to your problem. Go to the References subfolder in your project referencing the two assemblies. For the assembly with the global Util right click and press Properties. In the Aliases property you should have global. Change that for example to DLL1 or whatever. Now if you like to use the global Util in a file add the following before your using statements:

extern alias DLL;

Now you can use the global Util like that DLL.Util

like image 21
Muepe Avatar answered Oct 17 '22 05:10

Muepe


You will need to use the "extern alias" language feature. Check out this blog entry by Anson Horton.

(Or just see Jon's answer.)

like image 21
afrischke Avatar answered Oct 17 '22 07:10

afrischke


This error may also show up when upgrading a DevExpress project

  1. Close Visual Studio
  2. Clear Temporary ASP.NET Files directories by clearing the following folders:

    • C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
    • C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\
    • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\
    • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\
    • C:\Users\[your_user_name]\AppData\Local\Temp\Temporary ASP.NET Files\
    • Restart the World Wide Web Publishing service (Start menu\Settings\Control Panel\Administrative tools\Services).
  3. Clear the project's Bin and Obj folders and deploy new assemblies if it is necessary;

  4. Rebuild your application
like image 30
xameeramir Avatar answered Oct 17 '22 06:10

xameeramir