You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type 'type' in 'assembly' conflicts with the imported type 'type2' in 'assembly'. Using the type defined in 'assembly'.
14
14
15
-
This warning is issued when a type in a source file (file_2) conflicts with an imported type in file_1. The compiler uses the one in the source file.
15
+
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.
16
+
17
+
## What constitutes a conflict
18
+
19
+
A conflict occurs when two types have identical fully qualified names, meaning:
20
+
21
+
- They have the same namespace
22
+
- They have the same type name
23
+
- They're both accessible in the current compilation context
24
+
25
+
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.
16
26
17
-
## Example 1
27
+
## Example
28
+
29
+
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.
30
+
31
+
First, create a library that defines type `A`:
18
32
19
33
```csharp
20
34
// CS0436_a.cs
@@ -26,10 +40,8 @@ public class A {
26
40
}
27
41
```
28
42
29
-
## Example 2
43
+
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):
30
44
31
-
The following example generates CS0436.
32
-
33
45
```csharp
34
46
// CS0436_b.cs
35
47
// compile with: /reference:CS0436_a.dll
@@ -39,7 +51,7 @@ public class A {
39
51
System.Console.WriteLine("CS0436_b");
40
52
}
41
53
}
42
-
54
+
43
55
publicclassTest
44
56
{
45
57
publicstaticvoidMain()
@@ -50,8 +62,19 @@ public class Test
50
62
}
51
63
```
52
64
53
-
Compilation produces the following output:
65
+
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:
54
66
55
67
```console
56
68
CS0436_b
57
69
```
70
+
71
+
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`.
72
+
73
+
## How to resolve this warning
74
+
75
+
To resolve this warning, you can:
76
+
77
+
1. Rename one of the conflicting types.
78
+
1. Use a different namespace for one of the types.
79
+
1. Remove the reference to the assembly containing the conflicting type if it's not needed.
80
+
1. Use an extern alias to disambiguate between the two types if you need to use both (see [CS0433](/dotnet/csharp/language-reference/compiler-messages/cs0433) for examples of using extern aliases).
0 commit comments