다음을 통해 공유


컴파일러 오류 CS1705

어셈블리 'AssemblyName1'은 참조된 어셈블리 'AssemblyName2'보다 높은 버전의 'TypeName'을 사용합니다.

참조된 어셈블리의 버전 번호보다 높은 버전 번호의 형식에 액세스하고 있습니다. 대개 이 오류는 동일한 어셈블리의 두 버전을 실수로 사용하기 때문에 발생합니다.

예를 들어 Asmb1과 Asmb2라는 두 개의 어셈블리가 있다고 가정합니다. 어셈블리 Asmb1은 어셈블리 Asmb2의 버전 1.0을 참조합니다. 어셈블리 Asmb1은 또한 어셈블리 Asmb2 버전 2.0에 추가된 MyClass 클래스를 사용합니다. 컴파일러에는 참조 바인딩에 대한 통일된 규칙이 있으며 버전 1.0으로는 버전 2.0의 MyClass에 대한 참조를 충족시킬 수 없습니다.

예제

다음의 자세한 예제는 네 개의 코드 모듈로 구성되어 있습니다.

  • 버전 특성을 제외하고 동일한 두 개의 DLL

  • 처음 두 개를 참조하는 세 번째 DLL 입니다.

  • 동일한 DLL의 버전 1.0만을 참조하지만 버전 2.0의 클래스에 액세스하는 클라이언트입니다.

다음 코드는 동일한 DLL 중 첫 번째 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() {}  
}  

다음 코드는 AssemblyVersionAttribute 특성으로 지정된 어셈블리의 버전 2.0을 정의합니다.

// 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는 DLL 버전 1.0에서 Class1A의 별칭인 Class1 형식의 개체를 반환합니다. 두 번째 Return1B는 DLL 버전 2.0에서 Class1B의 별칭인 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 메서드에서 코드는 CS1705c.cs의 ClassC에 액세스합니다. 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

    이 명령을 사용할 때 프로그램이 컴파일되더라도 프로그램이 실행되지는 않습니다. 프로그램이 실행되게 하려면 <assemblyIdentity> and <codeBase> 자식 요소를 사용하는 <dependentAssembly> 요소를 포함하여 DLL 버전 1.0의 위치를 지정하는 애플리케이션 구성 파일을 제공합니다. 구성 파일에 대한 자세한 내용은 앱 구성을 참조하세요.

참고 항목