Could not load file or assembly "Newtonsoft.Json.Net" (Exception from HRESULT: 0x80131040)

Mike Barnes picture Mike Barnes · Apr 24, 2014 · Viewed 25.9k times · Source

When we installed a previous version the Neo4jClient via nuget we saw that Newtonsoft.Json version 4.5.0.0 was installed as a dependency. We also use other packages that require version 6.0.0.0 of Newtonsoft.Json and when we install them it overrides version 4.5.0.0.

When we start our app we get this error:

Unhandled Exception: System.ServiceModel.FaultException`1[System.ServiceModel.Ex
ceptionDetail]: 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's manifest definition does not match the assembly referenc
e. (Exception from HRESULT: 0x80131040)

We looked at all our configs and found nothing referencing version 4.5.0.0, however after taking a closer look at the Neo4jClient we found this.

using ildasm.exe from visual studion tools

Here is the packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AzureStorageClient" version="0.0.5.1829" targetFramework="net45" />
  <package id="CouchbaseNetClient" version="1.3.4" targetFramework="net45" />
  <package id="Elasticsearch.Net" version="1.0.0-beta1" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.20" targetFramework="net45" />
  <package id="Neo4jClient" version="1.0.0.652" targetFramework="net45" />
  <package id="NEST" version="1.0.0-beta1" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
</packages>

We have removed all packages, reinstalled, cleaned and rebuilt but with no avail. Is this the Neo4jClient that is causing this to happen or does the problem live somewhere else?

UPDATE What we have tried

  1. Removed all packages and re installed
  2. Cleaned and rebuilt solution
  3. Assembly redirect
  4. Tried looking for <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> but was not in the .csproj

Answer

Christoph Fink picture Christoph Fink · Apr 24, 2014

Have you tried assembly version redirect via app.config/web.config?

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <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>
    </assemblyBinding>
</runtime>