Compiler Error CS0433

类型 TypeName1 同时存在于 TypeName2 和 TypeName3 中。

在应用程序中引用的两个不同的程序集包含相同的命名空间和类型,这会产生混乱。

若要解决此错误,请使用 /reference (C# Compiler Options) 编译器选项的别名功能,或者不引用您的程序集。

此代码用歧义类型的第一个副本创建 DLL。

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

此代码用歧义类型的第二个副本创建 DLL。

// CS0433_2.cs
// compile with: /target:library
namespace TypeBindConflicts 
{
   public class AggPubImpAggPubImp {}
}

下面的示例生成 CS0433。

// CS0433_3.cs
// compile with: /reference:cs0433_1.dll /reference:cs0433_2.dll
using TypeBindConflicts;
public class Test 
{
   public static void Main() 
   {
      AggPubImpAggPubImp n6 = new AggPubImpAggPubImp();   // CS0433
   }
}

下面的示例演示如何使用 /reference 编译器选项的别名功能来解决此 CS0433 错误。

// CS0433_4.cs
// compile with: /reference:cs0433_1.dll /reference:TypeBindConflicts=cs0433_2.dll
using TypeBindConflicts;
public class Test 
{
   public static void Main() 
   {
      AggPubImpAggPubImp n6 = new AggPubImpAggPubImp();
   }
}