11

I am trying to do something pretty simple here, and I've been stuck on it for several hours. I feel like I've exhausted almost every option.

All I am trying to do is: JsonConvert.SerializeObject(model)

However, the resulting error is:

Exception thrown: 'System.IO.FileLoadException' in mscorlib.dll

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=982hs0cm1kd' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

However, in my project, I am referencing version 10.0.0.0. More Specifically, 10.0.2.0. When I checked my bin folder for the project, I can verify that the 10.0.2.0 dll is there. In packages.config, I have <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />

Things I have tried:

  1. Manually deleteing the bin/obj folders from the project and rebuilding
  2. Manually Modifying the Web.Config file to ensure the right version in the binding redirect.
  3. Updating the Reference Property 'Specific Version' to False
  4. Manually delete all of the files in C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root

I am really stuck here, and I can see this is a common problem as I found a lot of different approaches to fix it, however none have worked so far.

Any ideas?

Community
  • 1
  • 1
Tabrock
  • 1,120
  • 1
  • 20
  • 37
  • 5
    "However, in my project, I am referencing version 10.0.0.0. More Specifically, 10.0.2.0." That isn't "more specifically" - that's "differently". It sounds like *something* is still expecting 10.0.0.0, and is failing because it's finding 10.0.2.0. Could you put your assembly binding redirect in the question please? – Jon Skeet May 09 '17 at 16:52
  • 2
    Smells like a DLL hell problem. Have you tried making sure that all your code references the same lib and you not using another version in referenced code? – daveBM May 09 '17 at 16:55
  • I've ran into this issue and I had to run this command in npm console update-package Newtonsoft.Json -reinstall – nobody May 09 '17 at 16:57
  • In VS, in the properties window of the Newtonsoft.Json assembly in your project references, the path to the DLL the compiler is using is shown. What happens if you copy the DLL from this path into your bin folder or wherever your executable is being published (overwriting whatever DLL there might be already). Does the error still occurs then? –  May 09 '17 at 17:08
  • 1
    Looks like you forgot to add fusion log information which you collected investigating assembly loading exception - please make sure to [edit] post and include that log. – Alexei Levenkov May 09 '17 at 17:08
  • Or is perhaps another library used by your project also reliant on Newtonsoft.Json, but requires a different (older) version of it? –  May 09 '17 at 17:12
  • @AlexeiLevenkov You sure found this quick... I'm trying to get at the logs with fuslogvw, but I am not seeing any output. – Tabrock May 09 '17 at 18:47
  • @elgonzo there are other projects with different versions of Newtonsoft.Json, but within this project that is the only version. And yes, the package dll is the same as the bin dll. – Tabrock May 09 '17 at 18:47
  • You may need to restart IIS (if deploying to IIS) after turning on logging... or maybe restart VS if using dev server. Also check out https://blogs.msdn.microsoft.com/suzcook/2003/05/29/debugging-assembly-loading-failures/ for guidance. – Alexei Levenkov May 09 '17 at 19:54
  • Thank you, I will take a look! – Tabrock May 10 '17 at 19:02
  • That did the trick. MSDN article helped a lot to. – Tabrock May 10 '17 at 23:44
  • Please add an answer with the steps you took to help others that may have same issue. – Marshall Sep 27 '17 at 07:47

2 Answers2

3

In package manager console execute: Update-Package –reinstall Newtonsoft.Json.

source

MorenajeRD
  • 849
  • 1
  • 11
  • 27
2

Just had a similar issue. My website and a referenced project (I assume same for assembly) both required Newtonsoft.Json but they had slightly different versions.

Seems the website was winning out, so the site had that version installed and the referenced assembly failed to load "it's" version.

Made sure all the projects had the same version (Manage NuGet Packages for Solution) and worked.

Drew
  • 21
  • 2