編譯器錯誤 CS0433
更新:2007 年 11 月
錯誤訊息
TypeName2 和 TypeName3 兩者中都有型別 TypeName1
在您的應用程式內參考的兩個不同組件包含了相同的命名空間和型別,使其產生了模稜兩可 (Ambiguity) 的情況。
若要解決這項錯誤,請使用 /reference (匯入中繼資料) (C# 編譯器選項) 編譯器選項的別名功能,或者不要參考您的任何一個組件。
範例
這個程式碼會以第一個模稜兩可的型別建立 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 編譯器 (Compiler) 選項的別名功能來解決這個 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();
}
}