Compiler Error CS1705

Assembly 'AssemblyName1' uses 'TypeName' which has a higher version than referenced assembly 'AssemblyName2'

You are referencing a type that has a higher version number than the version number in a referenced assembly.

For example, you have two assemblies, A and B. A references a class myClass that was added to assembly B in version 2.0. But the reference to assembly B specifies version 1.0. The compiler has unification rules for binding references, and a reference to version 2.0 cannot be satisfied by version 1.0.

Example

This sample consists of four code modules:

  • Two DLLs that are identical except for a version attribute.

  • A DLL that references them.

  • A client.

The following is the first of the identical DLLs.

// CS1705_a.cs
// compile with: /target:library /out:c:\\cs1705.dll /keyfile:mykey.snk
[assembly:System.Reflection.AssemblyVersion("1.0")]
public class A 
{
   public void M1() {}
   public class N1 {}
   public void M2() {}
   public class N2 {}
}

public class C1 {}
public class C2 {}

The following is version 2.0 of the assembly, as specified by the AssemblyVersionAttribute attribute.

// CS1705_b.cs
// compile with: /target:library /out:cs1705.dll /keyfile:mykey.snk
using System.Reflection;
[assembly:AssemblyVersion("2.0")]
public class A 
{
   public void M2() {}
   public class N2 {}
   public void M1() {}
   public class N1 {}
}

public class C2 {}
public class C1 {}

Save this example in a file named CS1705ref.cs and compile it with the following flags: /t:library /r:A2=.\bin2\CS1705a.dll /r:A1=.\bin1\CS1705a.dll

// CS1705_c.cs
// compile with: /target:library /r:A2=c:\\CS1705.dll /r:A1=CS1705.dll
extern alias A1;
extern alias A2;
using a1 = A1::A;
using a2 = A2::A;
using n1 = A1::A.N1;
using n2 = A2::A.N2;
public class Ref 
{
   public static a1 A1() { return new a1(); }
   public static a2 A2() { return new a2(); }
   public static A1::C1 M1() { return new A1::C1(); }
   public static A2::C2 M2() { return new A2::C2(); }
   public static n1 N1() { return new a1.N1(); }
   public static n2 N2() { return new a2.N2(); }
}

The following sample references version 1.0 of the CS1705.dll assembly. But the statement Ref.A2().M2() references the A2 method in the class in CS1705_c.dll, which returns an a2, which is aliased to A2::A, and A2 references version 2.0 via an extern statement, thus causing a version mismatch.

The following sample generates CS1705.

// CS1705_d.cs
// compile with: /reference:c:\\CS1705.dll /reference:CS1705_c.dll
// CS1705 expected
class Tester 
{
   static void Main() 
   {
      Ref.A1().M1();
      Ref.A2().M2();
   }
}