Compiler Error CS0433

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 option or do not reference one of your assemblies.

This error can also occur if:

  • The @ Page directive has a CodeFile attribute when it should be a CodeBehind attribute.
  • Code is placed in an App_Code folder that shouldn't reside there.

Examples

This code creates the DLL with the first copy of the ambiguous type.

// CS0433_1.cs in CS0433_1.csproj  
// or compile with: /target:library  
namespace TypeBindConflicts
{  
   public class AggPubImpAggPubImp { }  
}  

This code creates the DLL with the second copy of the ambiguous type.

// CS0433_2.cs in CS0433_2.csproj  
// or compile with: /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.

<!-- CS0433_3.csproj -->
<ProjectReference Include="..\CS0433_1\CS0433_1.csproj" />  
<ProjectReference Include="..\CS0433_2\CS0433_2.csproj" />  
// CS0433_3.cs in CS0433_3.csproj  
// or compile with: /reference:cs0433_1.dll /reference:cs0433_2.dll  
using TypeBindConflicts;

public class Test
{  
   public static void Main()
   {  
      AggPubImpAggPubImp n6 = new AggPubImpAggPubImp();   // CS0433  
   }  
}  

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.

<!-- CS0433_4.csproj -->  
<ProjectReference Include="..\CS0433_1\CS0433_1.csproj">  
  <Aliases>CustomTypes</Aliases>
</ProjectReference>
<ProjectReference Include="..\CS0433_2\CS0433_2.csproj" />  
// CS0433_4.cs in CS0433_4.csproj  
// compile with: /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 n6 = new AggPubImpAggPubImp();
      
      // AggPubImpAggPubImp taken from CS0433_2.dll
      CustomTypes.TypeBindConflicts.AggPubImpAggPubImp n7 =
          new CustomTypes.TypeBindConflicts.AggPubImpAggPubImp();
   }  
}