My console application uses System.Net.Http.Formatting v5.1.0.0, which depends on Newtonsoft.Json v4.5.0.0. However, my application includes v6.0.0.0 Newtonsoft.Json (for other reasons).
To make System.Net.Http.Formatting use the new version of Newtonsoft.Json, I added reconfiguration of the assembly in App.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> ... <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
However, I get the following exception:
A first chance exception of type 'System.IO.FileLoadException' occurred in System.Net.Http.Formatting.dll Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The merge log shows that the correct assembly is loaded, but it fails due to a mismatch:
*** Assembly Binder Log Entry (2014.08.10. @ 13:13:25) *** The operation failed. Bind result: hr = 0x80131040. No description available. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe --- A detailed error log follows. === Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (Fully-specified) LOG: Appbase = file:///D:/ConsoleApplication1/bin/Debug/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = ConsoleApplication1.exe Calling assembly : System.Net.Http.Formatting, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///D:/ConsoleApplication1/bin/Debug/Newtonsoft.Json.DLL. LOG: Assembly download was successful. Attempting setup of file: D:\ConsoleApplication1\bin\Debug\Newtonsoft.Json.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: The assembly reference did not match the assembly definition found. ERR: Run-from-source setup phase failed with hr = 0x80131040. ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
What can I do to resolve this inconsistency? Thanks in advance.
Decision
There was nothing wrong with the redirect. The only hint was that it wasnβt even used in some way, although everything seemed to work as expected (note that the log even shows that the correct configuration file was loaded). The problem was that the assemblyBinding section contained this declaration for another assembly:
<qualifyAssembly partialName="log4net" fullName="log4net, 1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
This line solved this problem, but somehow violated Json forwarding. I donβt know why: the qualifyAssembly declaration is also considered correct.
However, deleting this declaration made the assembly redirect work ...