Show/Hide Toolbars

XSharp

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

 

You are accessing a type that has a higher version number than the version number in a referenced assembly. Typically, this error is caused by the accidental use of two versions of the same assembly.

 

For example, suppose that you have two assemblies, Asmb1 and Asmb2. Assembly Asmb1 references version 1.0 of assembly Asmb2. Assembly Asmb1 also uses a class MyClass that was added to assembly Asmb2 in version 2.0. The compiler has unification rules for binding references, and a reference to MyClass in version 2.0 cannot be satisfied by version 1.0.

Example

 

The following more detailed example consists of four code modules:

 

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

•A third DLL that references the first two.

•A client that references only version 1.0 of the identical DLLs, but accesses a class from version 2.0.

 

The following code creates the first of the identical DLLs. For information about how to generate a key file, see /keyfile (X# Compiler Options).

 

 

// XS1705a.prg  
 

Example

 

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

 

 

// XS1705b.prg  
 

 

Example

 

The following code references the two DLL versions that are defined in the preceding code. AssemblyA refers to the DLL created by XS1705a.prg (version 1.0). AssemblyB refers to the DLL created by XS1705b.prg (version 2.0). In ClassC, two methods are defined. The first, Return1A, returns an object of type Class1A, which is an alias for Class1 from version 1.0 of the DLL. The second, Return1B, returns an object of type Class1B, which is an alias for Class1 from version 2.0 of the DLL. The definition of Return1A creates a dependency on version 1.0; the definition of Return1B creates a dependency on version 2.0.

 

 

// XS1705c.prg  
 

 

 

Example

 

The following code generates compiler error XS1705. It references the DLL created by XS1705a.prg (version 1.0). However, in the Main method, the code accesses ClassC from XS1705c.prg. ClassC uses a type that is defined in XS1705b.prg (version 2.0). This causes compiler error XS1705 because the type has a version number for XS1705.dll that is higher than the referenced version of XS1705.dll.

 

 

// XS1705d.prg  
 

 

 

You can resolve the error in one of the following ways:

 

•Update the code so that all files use the same version of the DLL.

•Add a reference to version 2.0 of the DLL to XS1705d.prg by using the following command to compile:

 

xsc /reference:C:\\XS1705.dll /reference:XS1705.dll /reference:XS1705c.dll XS1705d.prg

 

Although the program compiles when you use this command, it still does not run. To enable the program to run, you can provide an application configuration file that includes a <dependentAssembly> element that uses <assemblyIdentity> and <codeBase> child elements to specify the location of version 1.0 of the DLL. For more information about configuration files, see Configuring Apps.