PRB: "FileLoadException" Error Message When the .NET Runtime Searches for Assemblies by Using the Probing Tag of the Application Configuration File (821626)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

SYMPTOMS

Assume the following:
  • An application references an assembly.
  • The assembly has multiple versions.
  • The assembly is located in a directory that the privatePath attribute of the probing tag specifies in the application configuration file.
When you run this application, you may receive the following System.IO.FileLoadException error message:
The located assembly's manifest definition with the name imported type instance does not match the assembly reference.

CAUSE

This problem occurs when the runtime probes for references to an assembly. The probing feature stops when the probe locates an assembly that has the following characteristics:
  • The assembly has the specified name.
  • The assembly is located in a directory that the privatePath attribute of the probing tag specifies in the application configuration file.
The runtime probes for references to the assembly in the directories that the privatePath attribute specifies. The runtime searches these directories in the order that they appear in the value of the privatePath attribute. During this probe, the runtime does not verify the version, the public key token, or the culture of the assembly. The runtime probes only for the assembly name.

RESOLUTION

To resolve this problem, modify the application configuration file to use the codeBase tag instead of the probing tag. The following is a sample of the modified configuration information:
<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="server" publicKeyToken="ae13fa4a5de1ffac" /> 
            <codeBase version="1.0.0.0" href="v1/server.dll"/>
            <codeBase version="2.0.0.0" href="v2/server.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>
Note You can locate the value of the publicKeyToken attribute of Server.dll by running the following command at a command prompt:

sn -Tp server.dll

The output of this command contains a value named 'Public key token'. Use this value for the value of the publicKeyToken attribute of the assemblyIdentity tag in the application configuration file.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Note The following steps assume that your computer has one application directory.
  1. Create a key pair file named Keypair.snk in the application directory by using the Strong Name tool (Sn.exe). To do this, run the following command at a command prompt:

    sn -k keypair.snk

  2. In a text editor (such as Notepad), paste the following code, and then save the file as Serverv1.0.cs in the application directory:
    using System.Reflection;
    
    [assembly: AssemblyVersion("1.0.0.0")]
    [assembly: AssemblyKeyFile("keypair.snk")]
    
    public class Server
    {
    	public string callServer()
    	{
    		return "This is version 1.0.0.0 of the server library.";
    	}
    }
  3. Run the following commands to build a library by using the file that you created in step 2. The first command creates a subdirectory named V1 in the application directory. The second command saves the library in this subdirectory.

    mkdir v1
    csc /target:library /out:v1\server.dll serverv1.0.cs

  4. In a text editor, paste the following code, and then save the file as Serverv2.0.cs in the application directory:
    using System.Reflection;
    
    [assembly: AssemblyVersion("2.0.0.0")]
    [assembly: AssemblyKeyFile("keypair.snk")]
    
    public class Server
    {
    	public string callServer()
    	{
    		return "This is version 2.0.0.0 of the server library.";
    	}
    }
  5. Run the following commands to build a library by using the file that you created in step 4. The first command creates a subdirectory named V2 in the application directory. The second command saves the library in this subdirectory.

    mkdir v2
    csc /target:library /out:v2\server.dll serverv2.0.cs

  6. In a text editor, paste the following code, and then save the file as Client.cs:
    using System;
    
    public class Client
    {
    	static void Main()
    	{
    		Server server = new Server();
    		Console.WriteLine(server.callServer());
    	}
    }
  7. Run the following command to build an executable (.exe) file by using file that you created in step 6. This command references the Server.dll library in the V2 subdirectory.

    csc /reference:server.dll /lib:v2 /nowarn:1607 client.cs

  8. In a text editor, paste the following configuration information, and then save the file as Client.exe.config:
    <configuration>
       <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <probing privatePath="v1;v2"/>
          </assemblyBinding>
       </runtime>
    </configuration>
  9. At a command prompt, run the Client.exe application.

    You receive the error message that is mentioned in the "Symptoms" section.
  10. In the Just-In-Time Debugging dialog box, click No, and then note the additional information that appears.

    This information is the contents of the Fusion log. The last line of this information appears similar to the following:

    WRN: Comparing the assembly name resulted in the mismatch: Major Version.

    The probe for the assembly stops at the version 1.0.0.0 Server.dll library that is located in the V1 directory. However, the executable file has been statically linked to the Server.dll library that is located in the V2 directory. This library is version 2.0.0.0.
The file load fails because the expected version of the assembly does not match the version that the probe locates.

REFERENCES

For more information about how the runtime locates assemblies, visit the following Microsoft Web site:
For more information about the probing tag and the codeBase tag in the runtime settings schema for configuration files, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/6/2003
Keywords:kberrmsg kbSchema kbConfig kbAppSetup kbprb KB821626 kbAudDeveloper