Skip to content

Commit c9a8e03

Browse files
CopilotBillWagnermeaghanlewis
authored
Clarify what constitutes a type conflict in CS0436 compiler warning documentation (#48863)
* Initial plan * Clarify what constitutes a conflict in CS0436 documentation Co-authored-by: BillWagner <[email protected]> * Apply suggestions from code review Co-authored-by: Meaghan Osagie (Lewis) <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Bill Wagner <[email protected]> Co-authored-by: Meaghan Osagie (Lewis) <[email protected]>
1 parent 9945432 commit c9a8e03

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

docs/csharp/misc/cs0436.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Compiler Warning (level 2) CS0436"
33
title: "Compiler Warning (level 2) CS0436"
4-
ms.date: 07/20/2015
4+
ms.date: 10/01/2025
55
f1_keywords:
66
- "CS0436"
77
helpviewer_keywords:
@@ -12,9 +12,23 @@ ms.assetid: c4135d9d-3511-4bbc-9540-48c2091f869c
1212

1313
The type 'type' in 'assembly' conflicts with the imported type 'type2' in 'assembly'. Using the type defined in 'assembly'.
1414

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.
1626

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`:
1832

1933
```csharp
2034
// CS0436_a.cs
@@ -26,10 +40,8 @@ public class A {
2640
}
2741
```
2842

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):
3044

31-
The following example generates CS0436.
32-
3345
```csharp
3446
// CS0436_b.cs
3547
// compile with: /reference:CS0436_a.dll
@@ -39,7 +51,7 @@ public class A {
3951
System.Console.WriteLine("CS0436_b");
4052
}
4153
}
42-
54+
4355
public class Test
4456
{
4557
public static void Main()
@@ -50,8 +62,19 @@ public class Test
5062
}
5163
```
5264

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:
5466

5567
```console
5668
CS0436_b
5769
```
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

Comments
 (0)