Application Configuration Files for dlls

To create an Application Configuration File (or here for Windows XP) for a DLL it is necessary to include the manifest resource ID in the name of the .config file.

E.g. to redirect attempts to load the 8.0.50608.0 version of VC++ CRT, referenced in the cpp.native.dll assembly of the following example:

app.exe
cpp.managed.dll
cpp.native.dll
Microsoft.VC80.CRT.manifest
msvcm80.dll
msvcp80.dll
msvcr80.dll

One needs to create a “cpp.native.dll.2.config” file (the number denotes a resource ID of the manifest, embedded into the module, which is almost always “2” for dlls):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
  <windows>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity
          name="Microsoft.VC80.CRT"
          publicKeyToken="1fc8b3b9a1e18e3b"
          type="win32"
          processorArchitecture="x86" />
        <bindingRedirect
          oldVersion="8.0.41204.256-8.0.50727.762"
          newVersion="8.0.50727.762" />
      </dependentAssembly>
    </assemblyBinding>
  </windows>
</configuration>

and put it in the same directory:

app.exe
cpp.managed.dll
cpp.native.dll
cpp.native.dll.2.config
Microsoft.VC80.CRT.manifest
msvcm80.dll
msvcp80.dll
msvcr80.dll

Creating app.exe.config doesn’t help, because the “wrong” dependencies are in the cpp.native.dll, and not in the app.exe itself.

Resources

To better understand mechanics behind locating side-by-side assemblies, one can refer to the .NET Fusion Workshop. 13. Unmanaged Assemblies by Richard Grimes and to monitor loading the application in question with the Process Monitor or FileMon.

And another useful tool in diagnosing side-by-side assemblies dependencies problems is a fresh version of the Dependency Walker.