型 'TypeName1' が 'TypeName2' と 'TypeName3' の両方に存在します
アプリケーション内で参照される 2 つの異なるアセンブリに同じ名前空間と型が含まれているため、あいまいさが生じています。
このエラーを解決するには、(References) コンパイラ オプションの別名機能を使用するか、アセンブリのいずれかを参照しないようにします。
このエラーは、次の場合にも発生する可能性があります。
@ Page
ディレクティブの属性がCodeBehind
でなければならないときに、CodeFile
属性になっている。- コードが、不適切な場所にある App_Code フォルダーに配置されている。
このコードは、あいまいな型の最初のコピーを使用して DLL を作成します。
// CS0433_1.cs in CS0433_1.csproj
// or compile with: /target:library
namespace TypeBindConflicts
{
public class AggPubImpAggPubImp { }
}
このコードは、あいまいな型の 2 つ目のコピーを使用して DLL を作成します。
// CS0433_2.cs in CS0433_2.csproj
// or compile with: /target:library
namespace TypeBindConflicts
{
public class AggPubImpAggPubImp { }
}
したがって、これら 2 つのライブラリ (CS0433_1.dll
と CS0433_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();
}
}
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。