Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies

9

First, It is not just duplicate. None of answers from following questions are working for me.

http://goo.gl/tS40cn
http://goo.gl/pH6v2T

I've just updated all my packages using Nuget Package Manager and I started receiving this error.

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. (Exception from HRESULT: 0x80131040)

My Package Config has:

<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />

Web.config includes this piece of code:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
  </dependentAssembly>

Properties from Reference for Newtonsoft.Json

enter image description here

According to the answers from the similar questions, I have tried followings:

  • Reinstalling package using Update-Package –reinstall Newtonsoft.Json
  • Removing dependentAssembly config from Web.config for Newtonsoft.Json
  • Changing newVersion to 6.0.0.0 and 7.0.0.0 in dependentAssembly. Doing so gave birth to new error.
  • Also tried Get-Project -All | Add-BindingRedirect. It changes newVersion for Newtonsoft.Json to 4.5.0.0. But issue remains unresolved.

Please help me fixing this.

c#
.net
json
asp.net-mvc
json.net
asked on Stack Overflow Sep 27, 2015 by shashwat

10 Answers

11

I know this is old, but I just ran into the same problem. My issue was that multiple projects in the solution used Newtonsoft.Json, but some were at different versions. I updated all of them to the most recent (9.0.1 as I type) and the problem went away.

Anyway... if anyone is still dealing with this, make sure to update the package in EVERY project in the solution.

HTH

answered on Stack Overflow Jan 31, 2017 by Casey Crookston • edited Mar 2, 2017 by Casey Crookston
2

Add Newtonsoft reference in my MVC project solves the problem for me.

answered on Stack Overflow Dec 17, 2016 by Zafar
2

After trying much of the above (and some other posts), I uninstalled with the package manager all of the following from the project affected:

Microsoft.AspNet.WebApi
Microsoft.AspNet.Client
Microsoft.AspNet.Core
Microsoft.AspNet.WebHost
Newtonsoft.Json

Then reinstalled Microsoft.AspNet.WebApi, which auto installed .Client, .Core, .WebHost, .Json.

answered on Stack Overflow Feb 2, 2017 by Kenmeister
1

Run Update-Package Newtonsoft.Json -Reinstall

It should remove the reference to your 4.5 version, and reinstall the newer version referenced in your package.config. It will also update the binding redirect, which should then be as follows:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>

Since you said in your question that you already tried this, you might want to first try removing the existing reference manually. You might also want to make sure the files aren't read-only on disk, or otherwise locked by source control.

answered on Stack Overflow Sep 28, 2015 by Matt Johnson • edited Sep 28, 2015 by Matt Johnson
0

run this command in the package manager console:

PM> Install-Package Newtonsoft.Json -Version 6.0.1
answered on Stack Overflow Sep 27, 2015 by codeWorm
0
  1. In your VS solution explorer, remove the Newtonsoft.Json reference.
  2. Download the 6.0 binary files at Newtonsoft binary files here
  3. Extract the files
  4. Add the Newtonsoft library manually. From Visual Studio, right click Reference and select Add Reference
  5. Click Browse
  6. Navigate to the extracted files under Net45 and select Newtonsoft.Json.dll
  7. If it does not work try using Net40 instead by going through the whole procedure again.
answered on Stack Overflow Sep 27, 2015 by Ronald Ramos
0

In my case, the following code was present in my local debug version of the solution, but not in my live server version of code. Adding the code to my server Web.config file fixed the problem.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

answered on Stack Overflow Oct 31, 2016 by Colin
0

I had this error myself, and first used Update-Package –reinstall Newtonsoft.Json -IncludePrerelease it didn't work, then used Install-Package Newtonsoft.Json . it worked.

answered on Stack Overflow Dec 5, 2016 by samira riazati
0

Change the config to as mentioned below:

answered on Stack Overflow Jan 5, 2018 by Ash18
0

check the 'Newtonsoft.Json' version in the project references. Add that version in the Web config. It will work. For Example: your Webconfig look like this:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly>

If your version in References is '9.0.0.0' change to this:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="9.0.0.0"/>
</dependentAssembly>
answered on Stack Overflow Jul 13, 2018 by SDK • edited Jul 13, 2018 by Bhargav Rao

User contributions licensed under CC BY-SA 3.0