共用方式為


編譯器錯誤 CS0433

類型 TypeName1 同時存在於 TypeName2 和 TypeName3 中

您的應用程式中參考了包含相同命名空間和類型的兩個不同組件,因而產生模稜兩可的情況。

若要解決此錯誤,請使用 (References) 編譯器選項的別名功能,或不參考其中一個組件。

可能發生此錯誤的原因有:

  • @ Page 指示詞應該是 CodeBehind 屬性時,它具有 CodeFile 屬性。
  • 程式碼置於 App_Code 資料夾中,該資料夾不應置於該處。

範例

此程式碼以第一個模稜兩可的類型建立 DLL。

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

此程式碼以第二個模稜兩可的類型建立 DLL。

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

因此,在專案中取用這兩個程式庫 (CS0433_1.dllCS0433_2.dll) 時,使用 AggPubImpAddPubImp 型別會模棱兩可並會導致編譯器錯誤 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  
   }  
}  

下列範例示範如何使用 /reference 編譯器選項的別名功能或 <ProjectReference> 中的 <Aliases> 功能來解決這個 CS0433 錯誤。

<!-- 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();
   }  
}