# Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference

191

Things I've tried after searching:

1. in Web.Config put a binding on the old version:

<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.1.0" />
</dependentAssembly>

2. Edit my .csproj file to make sure there is only one Newtonsoft reference

<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>

3. Search my computer for every Newtonsoft.Json.dll and delete every non 6.0.1 version and delete the contents of my temp folder

4. Repair/Reinstall the package in nuget manager console

It succeeds on building, but gets the error when going to the site.

EDIT

ok, so then I tried to reinstall like every nuget package, and it seems to have added back the 4.5 version of the newtonsoft.json.dll, but I'm getting the same error. My project's Target freamework is .NET 4.5.1 and here is the stack trace I'm getting now:

Server Error in '/' Application.

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Newtonsoft.Json' could not be loaded.

Stack Trace:

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170 System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285 System.Web.Compilation.BuildManager.ExecutePreAppStart() +153 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

json
json.net
.net-assembly
asked on Stack Overflow Mar 27, 2014 by noobieDev • edited Oct 3, 2018 by Andrea

253

To solve this, I ensured all my projects used the same version by running the following command and checking the results:

update-package Newtonsoft.Json -reinstall


And, lastly I removed the following from my web.config:

  <dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>


If you want to ensure all your Newtonsoft.Json packages are the same version, you can specify the version like so:

update-package Newtonsoft.Json -version 6.0.0 -reinstall

answered on Stack Overflow Nov 12, 2014 by user1477388 • edited Nov 19, 2015 by user1477388
78

I am using Newtonsoft.Json v6.0.3, but this is what I had to do in my Web.config file:

<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>


Note that even though I am using 6.0.3, I had to put in newVersion="6.0.0.0"

In my packages.config file I have:

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

answered on Stack Overflow Jun 24, 2014 by CraigV • edited Jun 24, 2014 by Gergo Erdosi
57

I tried the following after having already ensured that my computer had the same version in all locations and that my projects were all pointing to the same reference path. I had also made sure that the binding of the old version was their and bound to the current version of dll that I had.

I work in an environment with a strict framework and the framework team often upset the versioning with the different dll's.

How I fixed this issue was to run the package manager console within visual studio (2013). From there I ran the following command:

update-package Newtonsoft.Json -reinstall


followed by

update-package Newtonsoft.Json


This went through and updated all of my config files and relevant project files. Forcing them all to the same version of the dll. Which was initially version 4.5 before updating again to get the latest.

answered on Stack Overflow Feb 3, 2015 by Samuel
25

I had the same error message and, like you mentioned, it was due to different versions of the Newtonsoft.Json.dll being referenced.

Some projects in my MVC solution used the NuGet package for version 4 of that dll.

I then added a NuGet package (for Salesforce in my case) that brought Newtonsoft.Json version 6 with it as a dependency to one of the projects. That was what triggered the problem for me.

To clean things up, I used the Updates section in the NuGet Package Manager for the solution (off Tools menu or solution right-click) to update the Json.Net package throughout the solution so it was the same version for all projects.

After that I just checked the App Config files to ensure any binding redirect lines were going to my chosen version as below.

<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

answered on Stack Overflow May 16, 2014 by S__
16

Ok, I think I got it to work now. I deleted every Newtonsoft.Json.dll on my machine that wasn't the latest version that I could find, made sure I had the latest version in NuGet, and build it and made sure that was the latest one in the bin folder, and I left the changes in the web.config and the .csproj. Now I'm on to another error, so it must be working..

answered on Stack Overflow Apr 24, 2014 by noobieDev
4

I have tried the steps by Oleg, and they worked for my same situation.

Steps:

1. Run update-package Newtonsoft.Json -reinstall in Package Manager.

2. Delete your bin by enabling viewing the hidden files and deleting the bin folder.

3. Close your Visual Studio and re-open it.

4. Now run your project again. I believe it should be ok!

answered on Stack Overflow Jul 7, 2017 by Matthew Cavallo • edited Jul 8, 2017 by Azeem
4

By commenting it out this part on my web.config solved my problem:

<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>


But of course you need to make sure you have updated or you have the right version by doing this in your package manager console:

update-package Newtonsoft.Json -reinstall

answered on Stack Overflow Oct 24, 2017 by Willy David Jr
4

You can solve the issue by adding below lines in web.config file.

 <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

answered on Stack Overflow Nov 10, 2017 by Jineesh Uvantavida
3

In my case it was just a matter of:

Tools -> NuGet Package Manager -> Package Manager Settings -> Clear Cache


The problem was caused when I remapped a TFS folder.

answered on Stack Overflow Jun 1, 2015 by daniloquio
3

What actually helped me was to turn off the Resharper build and to use the VisualStudio Re-Build option on my project.

answered on Stack Overflow Nov 27, 2017 by Shaulian
2

if you're working with some kind of subversion: delete the project and re-download it, it worked for me :S

answered on Stack Overflow Sep 24, 2014 by ch2o
2

I Don't know why, but in my case, even if I remove bin folder from project, when I build project it copies old version of newtonsoft.json, I copied new version's dll from packages folder and It solves for now.

answered on Stack Overflow Nov 8, 2015 by mesut
1

I had the same issue on a Test Project that had reference to an MVC 5 project. This happened after I merged with an MVC 5 project. I fixed it by installing Visual studio 2012 updates as explained here in Andre's response.

• In your visual studio go to
2. Select "Updates" in the accordion list on the left.
4. Update to the newest version
answered on Stack Overflow Mar 27, 2015 by Michael Kassa • edited May 23, 2017 by Community
1

None of the answers, including the checked one did not work for me.

The solution was far more simple. I first removed the references from my BUS layer. Then deleted the dll's from the project (to make sure it's gone), then reinstalled JSON.NET from nuget packeges. And, the tricky part was, "turning it off and on again".

I just restarted visual studio, and there it worked!

So, if you try everything possible and still can't solve the problem, just try turning visual studio off and on again, it might help.

answered on Stack Overflow Jun 1, 2015 by Zafer Sernikli
1

https://stackoverflow.com/a/12011221/150370

(TL;DR: Remove xml namespace from configuration tag in your config file. Otherwise binding redirects will be ignored)

answered on Stack Overflow Jun 9, 2016 by German Latorre • edited May 23, 2017 by Community
1

In some cases if you delete your Bin and Obj folders will solve this problem.

answered on Stack Overflow May 9, 2017 by Ivan Ruski
1

I resolved it by remove lower version of Newtonsoft.json.dll in bin folder and added Newtonsoft.json.dll V6.0.0.0 and removed the following web.config elements

<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>

answered on Stack Overflow Jul 8, 2017 by user2017678
1

I got the same problem with dotnet core and managed to fix it by clearing the NuGet cache.

Open the powershell and enter the following command.

dotnet nuget locals all --clear


Then I closed Visual Studio, opened it again and entered the following command into the Package Manager Console:

Update-Package


NuGet should now restore all packages and popultes the nuget cache again.

After that I was able to build and start my dotnet core webapi in a Linux container.

answered on Stack Overflow Oct 4, 2018 by datoml
1

from Tools>>NuGet Package Manager>>Manage Package for solution update Newtonsoft.Json of all solutions to latest Version

answered on Stack Overflow Dec 25, 2018 by Goda Kotb
0

Easy steps. (1)Run "update-package Newtonsoft.Json -reinstall" in package manager.

(2)Delete you bin by enabling viewing the hidden files and deleting the bin folder.

(3)Close your visual studio and re-open it.

(4) Now run your project again. I believe it should be ok

answered on Stack Overflow Apr 15, 2015 by Odeyinka Olubunmi
0

I hit this problem because I had: project A (a desktop .exe) refer to project B (a portable .dll). A & B had different versions of JSON.Net, and so there was a loader conflict. Once I made all the versions of JSON.net the same, it worked. (This is in effect what some of the solutions above are doing - I'm just calling out why it works)

answered on Stack Overflow May 16, 2015 by Mike S
0

I struggled with this recently with and older project.

I managed to track down the problem after checking what version of the dll that actually was in the bin folder.

I had a post-build script that copied dependent assemblies from a dll library folder to the bin folder. A common setup from the days before nuget.

So every time I built the post-build script replaced the correct version of Json.net with the older one

answered on Stack Overflow May 27, 2015 by Fredrik Stolpe
0

I had exactly the same issue and Visual Studio 13 default library for me was 4.5, so I have 2 solutions one is take out the reference to this in the webconfig file. That is a last resort and it does work.

The error message states there is an issue at this location /Projects/foo/bar/bin/Newtonsoft.Json.DLL. where the DLL is! A basic property check told me it was 4.5.0.0 or alike so I changed the webconfig to look upto 4.5 and use 4.5.

answered on Stack Overflow Aug 13, 2015 by Mcole1976
0

None of these options worked for me, in the end it was;

Test > Test Settings > *.testrunconfig

<DeploymentItem filename="packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll" />


Make sure the path and version is correct for your setup.

answered on Stack Overflow Sep 7, 2015 by Daniel Haselden
0

I had the same issue. I created a web api project and then upgraded it from .net 4.5.1 to .net 4.6.1. Closing the IDE, stopping IIS, and deleting contents of the C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ dir fixed the issue.

HTH

0

This problem was not solved for me by refreshing NuGet Packages or by performing a "Clean" on the project. It was solved by clearing out the "obj" folder manually.

answered on Stack Overflow Jun 29, 2017 by Alexander P. Brown
0

Here is my solution to this problem,make sure the version number in appconfig or packageconfig is same as the reference version in your references. See here

answered on Stack Overflow Oct 12, 2017 by (unknown user)
0

In my case, at the message of error was "version 6.0.0", but this version is not available to install, so i installed the "6.0.1 version" at my project and solved my problem.

install-package Newtonsoft.Json -Version 6.0.1 -Project MyProjectX

answered on Stack Overflow Dec 12, 2018 by Fabricio Leite
0

my problem was the newVersion in this code in web.config was not correct

<dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.1.0" />


you can see the version of Newtonsoft.Json package in nuget package manager and use it.

answered on Stack Overflow Feb 10, 2019 by rzb
0

the solution that solved my problem for this is

goto references->right click Newtonsoft.json--goto properties and check the version

this same version should be in

<dependentAssembly>