3

I get the following exception every time I run my project:

An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll but was not handled in user code Additional information: 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 reference. (Exception from HRESULT: 0x80131040)

I tried almost every solution I could find on the web.

My packages.config file:

<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net451" />

and this in web.config file:
 <assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed"  />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
      </dependentAssembly>

I even used the following commands to update/reinstall json.net:

update-package Newtonsoft.Json -reinstall
update-package Newtonsoft.Json

What else I can try?

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
Suha Alhabaj
  • 101
  • 2
  • 11
  • I am not sure but it did not work either. – Suha Alhabaj Feb 16 '16 at 20:48
  • I just checked, for Json.NET 8.0.2 `typeof(JsonSerializer).Assembly.FullName` has `Version=8.0.0.0`. So give that one a try. – dbc Feb 16 '16 at 20:50
  • See also https://stackoverflow.com/questions/22685530/could-not-load-file-or-assembly-newtonsoft-json-or-one-of-its-dependencies-ma. Of course the version number is inappropriate for Json.NET 8.0.2 in that answer. – dbc Feb 16 '16 at 20:52
  • You are right about the version number, I got this message when I try to reinstall: Successfully added 'Newtonsoft.Json 8.0.2' to Prodb1. But the exception still coming up in running time. – Suha Alhabaj Feb 16 '16 at 21:16

4 Answers4

3

Change your binding redirect newVersion and oldVersion to match the version of Json.net your are trying to use:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed"  />
    <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
  </dependentAssembly>

4.5 is the framework version, not the version of Json.net

NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
  • I still have the exception. Does this have anything to do with this message ? File visual studio 2013\Projects\Prodb1\packages\Newtonsoft.Json.8.0.2\tools\install.ps1 cannot be loaded because running scripts is disabled on this system. – Suha Alhabaj Feb 16 '16 at 21:25
  • Still with the additional information, or has it changed at all? – NikolaiDante Feb 16 '16 at 21:26
  • Are you able to share your code as a [mvce](http://stackoverflow.com/help/mcve). At the moment I can't recreate your exact scenario locally. – NikolaiDante Feb 16 '16 at 21:43
0

Thanks everyone, I found the problem. I did not add culture="neutral" when I put this in web.config.

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed"  />
    <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
  </dependentAssembly>
Suha Alhabaj
  • 101
  • 2
  • 11
0

I had this issue and upon closer inspection I realized that somehow Newtonsoft had gotten added twice as a

<dependentAssembly>..</dependentAssembly>

in my web.config file. I had version 8.0 and 9.0 entries. I believe the 2nd entry was created when I updated from 8.0 to 9.0. A new entry was automatically created, however the old entry was not removed.

Pete
  • 267
  • 3
  • 8
0

I had the same issue holding up I just installed the Nuget Package 'Newtonsoft.json', for my project. And it get solved