How to cope with the Newtonsoft.Json 6 binding redirect issue in custom module development?

Topics: Core, Writing modules
Sep 18, 2014 at 2:30 PM
Edited Sep 18, 2014 at 6:59 PM
I'm writing a custom module which contains a field (see: https://orchard.codeplex.com/discussions/567717).

I can see the well known error: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

I'm using a binding redirect in my module:
<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
This is the one error that really keeps coming back at me when building custom modules and I have no proper way of solving it.

As for my current issue regarding this error message; I tried rebuilding, updating my newtonsoft.json package but the error remains.

The only thing what I can think of as being the problem is this:

_I'm using the code in a driver which is called by the ContentFieldDriver.UpdateEditorShape() method which on its turn is in Orchard.Framework assembly. This assembly also references Newtonsoft.Json (however the 4.5 version in the /lib folder) and therefore conflicts._

But even if the above would be the root issue I'd don't know how to solve it... Edit the Framework web.config and add a bindingredirect there? Doesn't sound feasible. Any ideas?


For reference, this is the bind log:

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///C:/.../src/Orchard.Web/
LOG: Initial PrivatePath = C:...\src\Orchard.Web\bin

Calling assembly : MyCustomField, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:...\src\Orchard.Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/28eb2094/a18aa767/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/28eb2094/a18aa767/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/.../src/Orchard.Web/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.