Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 306
shashwat Avatar asked Sep 27 '15 10:09

shashwat


People also ask

Can not load file or assembly?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

What is Newtonsoft JSON?

The Newtonsoft. JSON namespace provides classes that are used to implement the core services of the framework. It provides methods for converting between . NET types and JSON types.


3 Answers

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

like image 81
Casey Crookston Avatar answered Oct 08 '22 01:10

Casey Crookston


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

like image 2
Zafar Avatar answered Oct 08 '22 00:10

Zafar


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.

like image 2
Kenmeister Avatar answered Oct 08 '22 02:10

Kenmeister