어셈블리 'AssemblyName1'은 참조된 어셈블리 'AssemblyName2'보다 높은 버전을 가진 'TypeName'을 사용합니다.
참조된 어셈블리의 버전 번호보다 버전 번호가 높은 형식에 액세스합니다. 일반적으로 이 오류는 동일한 어셈블리의 두 버전을 실수로 사용하여 발생합니다.
예를 들어 Asmb1 및 Asmb2라는 두 개의 어셈블리가 있다고 가정합니다. 어셈블리 Asmb1은 어셈블리 Asmb2의 버전 1.0을 참조합니다. 어셈블리 Asmb1은 버전 2.0에서 어셈블리 Asmb2에 추가된 클래스 MyClass 도 사용합니다. 컴파일러에는 바인딩 참조에 대한 통합 규칙이 있으며 버전 1.0에서는 버전 2.0에 대한 참조 MyClass 를 충족할 수 없습니다.
예시
다음 보다 자세한 예제는 4개의 코드 모듈로 구성됩니다.
- 버전 특성을 제외하고 동일한 두 개의 DLL입니다.
- 처음 두 가지를 참조하는 세 번째 DLL입니다.
- 동일한 DLL의 버전 1.0만 참조하지만 버전 2.0에서 클래스에 액세스하는 클라이언트입니다.
다음 코드는 동일한 DLL 중 첫 번째를 만듭니다. 키 파일을 생성하는 방법에 대한 자세한 내용은 KeyFile (C# 컴파일러 옵션)을 참조하세요.
// CS1705a.cs
// Compile by using the following command:
// csc /target:library /out:C:\\CS1705.dll /keyfile:mykey.snk CS1705a.cs
// The DLL is created in the C:\ directory.
// The AssemblyVersion attribute specifies version 1.0 for this DLL.
[assembly:System.Reflection.AssemblyVersion("1.0")]
public class Class1
{
public void Method1() {}
}
다음 코드는 특성에 지정된 대로 어셈블리 버전 2.0을 AssemblyVersionAttribute 정의합니다.
// CS1705b.cs
// Compile by using the following command:
// csc /target:library /out:CS1705.dll /keyfile:mykey.snk CS1705b.cs
// The DLL is created in the current directory.
// The AssemblyVersion attribute specifies version 2.0 for this DLL.
[assembly:System.Reflection.AssemblyVersion("2.0")]
public class Class1
{
public void Method1() { }
}
다음 코드는 이전 코드에 정의된 두 DLL 버전을 참조합니다.
AssemblyA 는 CS1705a.cs(버전 1.0)에서 만든 DLL을 나타냅니다.
AssemblyB 는 CS1705b.cs(버전 2.0)에서 만든 DLL을 나타냅니다. 에서 ClassC두 가지 메서드가 정의됩니다. 첫 번째 , Return1A형식 Class1A의 개체를 반환합니다. 이 개체는 DLL 버전 1.0의 별칭 Class1 입니다. 두 번째 , Return1B형식 Class1B의 개체를 반환합니다. 이 개체는 DLL 버전 2.0의 별칭 Class1 입니다. 정의 Return1A 는 버전 1.0에 대한 종속성을 만듭니다. 정의 Return1B 는 버전 2.0에 대한 종속성을 만듭니다.
// CS1705c.cs
// Compile by using the following command. AssemblyA refers to the DLL created by
// CS1705a.cs (version 1.0). AssemblyB refers to the DLL created by CS1705b.cs
// (version 2.0).
// csc /target:library /r:AssemblyA=C:\\CS1705.dll /r:AssemblyB=CS1705.dll CS1705c.cs
extern alias AssemblyA;
extern alias AssemblyB;
// Class1A is an alias for type Class1 from VS1705a.cs, which is in version 1.0
// of the assembly. Class1B is an alias for type Class1 from CS1705b.cs, which
// is in version 2.0 of the assembly.
using Class1A = AssemblyA::Class1;
using Class1B = AssemblyB::Class1;
// Method Return1A in ClassC returns an object of type Class1A, which is
// Class1 from version 1.0 of the DLL. Method Return1B returns an object
// of type Class1B, which is Class1 from version 2.0 of the DLL.
public class ClassC
{
// The following line creates a dependency on version 1.0 of CS1705.dll.
// This is not the source of the problem when ClassC is accessed from
// CS1705d.cs because CS1705d.cs references version 1.0 of the DLL.
// Therefore, type Class1A and the assembly have the same version.
public static Class1A Return1A() { return new Class1A(); }
// The following line creates a dependency on version 2.0 of CS1705.dll.
// This causes compiler error CS1705 when ClassC is accessed from
// CS1705d.cs, because CS1705d.cs does not reference version 2.0 of the
// DLL. Class1B is the alias for Class1 in version 2.0, and CS1705d.cs
// references version 1.0.
public static Class1B Return1B() { return new Class1B(); }
}
다음 코드는 컴파일러 오류 CS1705를 생성합니다. CS1705a.cs(버전 1.0)에서 만든 DLL을 참조합니다. 그러나 Main 메서드에서는 ClassC 코드를 CS1705c.cs에서 액세스합니다.
ClassC 는 CS1705b.cs(버전 2.0)에 정의된 형식을 사용합니다. 이로 인해 컴파일러 오류 CS1705가 발생합니다. 형식에 참조된 CS1705.dll버전보다 높은 CS1705.dll 버전 번호가 있기 때문입니다.
// CS1705d.cs
// Compile by using the following command:
// csc /reference:C:\\CS1705.dll /reference:CS1705c.dll CS1705d.cs
// C:\\CS1705.dll is version 1.0 of the assembly.
class Tester
{
static void Main()
{
// Return1A returns a type defined in version 1.0.
ClassC.Return1A().Method1();
// Return1B returns a type defined in version 2.0.
ClassC.Return1B().Method1();
}
}
다음 방법 중 하나로 오류를 해결할 수 있습니다.
모든 파일이 동일한 버전의 DLL을 사용하도록 코드를 업데이트합니다.
다음 명령을 사용하여 컴파일하여 CS1705d.cs DLL 버전 2.0에 대한 참조를 추가합니다.
csc /reference:C:\\CS1705.dll /reference:CS1705.dll /reference:CS1705c.dll CS1705d.cs이 명령을 사용할 때 프로그램이 컴파일되지만 여전히 실행되지 않습니다. 프로그램을 실행할 수 있도록 하려면 사용하는
<dependentAssembly>요소와 자식 요소를 포함하는<codeBase>애플리케이션 구성 파일을 제공하여 DLL 버전 1.0의 위치를 지정할 수 있습니다. 구성 파일에 대한 자세한 내용은 앱 구성을 참조하세요.
참고하십시오
.NET