1

The typical way of creating an assembly redirect is by using bindingRedirect in app.config or dllname.dll.config. Alternatively, many posts on MSDN say that you can do so programmatically by using AssemblyResolve (I bind the event as early as possible, i.e. in <Module>.cctor).

What these posts don't tell you is that if an assembly is strongly named (in my case FSharp.Core 4.3 that must be redirected to 4.4), the AssemblyResolve method does not seem to work. Checking the Fusion Log Viewer shows an error indicating that there is a version mismatch after AssemblyResolve:

=== Pre-bind state information ===
LOG: DisplayName = FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///D:/Projects/ThisProj/
LOG: DEVPATH = C:\ProgramData\Red Gate\.NET Reflector\DevPath
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = R:\TMP\nunit20\ShadowCopyCache\39776_635854331778854585
LOG: AppName = Tests_913980014
Calling assembly : FsUnit.NUnit, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Did not find assembly in DEVOVERRIDE path C:\ProgramData\Red Gate\.NET Reflector\DevPath
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Projects/ThisProj/FSharp.Core.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\Projects\ThisProj\FSharp.Core.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

In most typical scenarios this is not a problem and I can settle with the .config approach, however, if you compile a project that references other projects with an app.config Visual Studio will only create one targetassemblyname.config for the final project, but won't do so for each individual assembly referenced, resulting in runtime binding issues for the final project (which in itself can be resolved by creating a post-build copy event).

This is also a problem when another application is trying to load an individual DLL from my project. Either because the config file is simply not there or, if the DLL is "copied around", the dll-config is not copied with.

Is there some workaround that can force the CLR to load the assembly I give to them, irrespective or version, just like the bindingRedirect works?

Abel
  • 56,041
  • 24
  • 146
  • 247

0 Answers0