Skip to content

Update CS0433 documentation to prioritize extern alias over csc compiler options #47307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions docs/csharp/language-reference/compiler-messages/cs0433.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The type TypeName1 exists in both TypeName2 and TypeName3

Two different assemblies referenced in your application contain the same namespace and type, which produces ambiguity.

To resolve this error, use the alias feature of the ([**References**](../compiler-options/inputs.md#references)) compiler option or do not reference one of your assemblies.
To resolve this error, use the `extern alias` feature with project reference aliases or do not reference one of your assemblies. You can also use the alias feature of the ([**References**](../compiler-options/inputs.md#references)) compiler option when compiling directly with the C# compiler.

This error can also occur if:

Expand All @@ -27,7 +27,7 @@ This error can also occur if:

```csharp
// CS0433_1.cs in CS0433_1.csproj
// or compile with: /target:library
// compile with: dotnet build or /target:library
namespace TypeBindConflicts
{
public class AggPubImpAggPubImp { }
Expand All @@ -38,14 +38,14 @@ namespace TypeBindConflicts

```csharp
// CS0433_2.cs in CS0433_2.csproj
// or compile with: /target:library
// compile with: dotnet build or /target:library
namespace TypeBindConflicts
{
public class AggPubImpAggPubImp { }
}
```

So, when consuming these two libraries (`CS0433_1.dll` and `CS0433_2.dll`) in the project, using the `AggPubImpAddPubImp` type will be ambiguous and will lead to compiler error `CS0433`.
So, when consuming these two libraries (`CS0433_1.dll` and `CS0433_2.dll`) in the project, using the `AggPubImpAggPubImp` type will be ambiguous and will lead to compiler error `CS0433`.

```xml
<!-- CS0433_3.csproj -->
Expand All @@ -55,7 +55,7 @@ namespace TypeBindConflicts

```csharp
// CS0433_3.cs in CS0433_3.csproj
// or compile with: /reference:cs0433_1.dll /reference:cs0433_2.dll
// compile with: dotnet build or /reference:cs0433_1.dll /reference:cs0433_2.dll
using TypeBindConflicts;

public class Test
Expand All @@ -67,7 +67,11 @@ public class Test
}
```

The following example shows how you can use the alias feature of the **/reference** compiler option or `<Aliases>` feature in `<ProjectReference>` to resolve this CS0433 error.
The following example shows how you can use the `extern alias` feature with project references to resolve this CS0433 error. This is the recommended approach for modern .NET projects.

### Step 1: Add an alias to one of the project references

First, modify your project file to add an alias to one of the conflicting project references:

```xml
<!-- CS0433_4.csproj -->
Expand All @@ -76,21 +80,25 @@ public class Test
</ProjectReference>
<ProjectReference Include="..\CS0433_2\CS0433_2.csproj" />
```

### Step 2: Use the extern alias in your code

Then, use the `extern alias` directive and qualified type names to distinguish between the two types:

```csharp
// CS0433_4.cs in CS0433_4.csproj
// compile with: /reference:cs0433_1.dll /reference:CustomTypes=cs0433_2.dll
// compile with: dotnet build or /reference:cs0433_1.dll /reference:CustomTypes=cs0433_2.dll
extern alias CustomTypes;
using TypeBindConflicts;

public class Test
{
public static void Main()
{
// AggPubImpAggPubImp taken from CS0433_1.dll
// AggPubImpAggPubImp taken from CS0433_2.dll (no alias, default global namespace)
AggPubImpAggPubImp n6 = new AggPubImpAggPubImp();

// AggPubImpAggPubImp taken from CS0433_2.dll
// AggPubImpAggPubImp taken from CS0433_1.dll (via CustomTypes alias)
CustomTypes.TypeBindConflicts.AggPubImpAggPubImp n7 =
new CustomTypes.TypeBindConflicts.AggPubImpAggPubImp();
}
Expand Down
Loading