Microsoft KB Archive/821626

= PRB: &quot;FileLoadException&quot; Error Message When the .NET Runtime Searches for Assemblies by Using the Probing Tag of the Application Configuration File =

Article ID: 821626

Article Last Modified on 6/6/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-



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  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:        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.



Steps to Reproduce the Behavior
Note The following steps assume that your computer has one application directory.  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

  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(&quot;1.0.0.0&quot;)] [assembly: AssemblyKeyFile(&quot;keypair.snk&quot;)]

public class Server {   public string callServer {       return &quot;This is version 1.0.0.0 of the server library.&quot;; } } </li> 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

</li>  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(&quot;2.0.0.0&quot;)] [assembly: AssemblyKeyFile(&quot;keypair.snk&quot;)]

public class Server {   public string callServer {       return &quot;This is version 2.0.0.0 of the server library.&quot;; } } </li> 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

</li>  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); } } </li> 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

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

You receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li> 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:

<pre class="fixed_text">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.</li></ol>

The file load fails because the expected version of the assembly does not match the version that the probe locates.

<div class="references_section">