Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 905
Mike Barnes Avatar asked Apr 24 '14 12:04

Mike Barnes


People also ask

How to fix ‘could not load file or assembly NewtonSoft JSON’ error?

If the Newtonsoft.Json Package is outdated then the ‘Could not load file or assembly Newtonsoft.Json’ error may appear. So we check the version of the Newtonsoft.Json Package and update it to the latest one.

What is the NewtonSoft JSON error?

This error mainly occurs when the DNN website has an incorrect version of the Newtonsoft.Json package in its configuration. At Bobcares, we often get requests to fix DNN errors, as a part of our Server Management Services. Today, let’s see how our Support Engineers fix the error for our customers. When does the Newtonsoft.Json Error occur?

What is the NuGet version of the NewtonSoft JSON?

The packages.config file is used by NuGet, a package manager. With this file, the NuGet tracks the packages and their versions installed in the project. When installing the Newtonsoft.Json from the NuGet Manager, it was showing version 10.0.3 and inside the packages.config file, it was also showing the same version:

Why is JSON not working on my website?

Mainly JSON shows this kind of error when there is a difference in the version specified on the web.config file and its original version of the JSON package. Other reasons for the error are when the code is missing in the web.config file and the outdated version.


1 Answers

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>
like image 151
Christoph Fink Avatar answered Sep 22 '22 11:09

Christoph Fink