Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The type 'type' in 'assembly' conflicts with the imported type 'type2' in 'assembly'. Using the type defined in 'assembly'.
This warning occurs when a type defined in your source code has the same fully qualified name (namespace and type name) as a type imported from a referenced assembly. When this name conflict occurs, the compiler uses the locally defined type from your source file and ignores the imported type.
What constitutes a conflict
A conflict occurs when two types have identical fully qualified names, meaning:
- They have the same namespace
- They have the same type name
- They're both accessible in the current compilation context
The conflict is determined solely by the type's fully qualified name, not by its implementation details. Two types with the same name but different implementations (such as different methods, properties, or field values) still conflict. The compiler can't use both types simultaneously because they have the same identity.
Example
The following example demonstrates CS0436. In this scenario, a type A is defined in an external library and also locally in the source file. Even though the two types have different implementations (they print different strings), they conflict because they share the same fully qualified name.
First, create a library that defines type A:
// CS0436_a.cs
// compile with: /target:library
public class A {
public void Test() {
System.Console.WriteLine("CS0436_a");
}
}
Then, compile the following code that defines another type A and references the library. The compiler issues CS0436 because both types have the fully qualified name A (in the global namespace):
// CS0436_b.cs
// compile with: /reference:CS0436_a.dll
// CS0436 expected
public class A {
public void Test() {
System.Console.WriteLine("CS0436_b");
}
}
public class Test
{
public static void Main()
{
A x = new A();
x.Test();
}
}
When you compile and run this code, the compiler uses the locally defined A (from CS0436_b.cs) and issues a warning. The output is:
CS0436_b
Note that the conflict exists even though the two A types have different implementations. The difference in the string literal ("CS0436_a" versus "CS0436_b") doesn't prevent the conflict. What matters is that both types have the same fully qualified name A.
How to resolve this warning
To resolve this warning, you can:
- Rename one of the conflicting types.
- Use a different namespace for one of the types.
- Remove the reference to the assembly containing the conflicting type if it's not needed.
- Use an extern alias to disambiguate between the two types if you need to use both (see CS0433 for examples of using extern aliases).