Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix json.net (Newtonsoft.Json) runtime file load exception

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?

like image 898
Suha Alhabaj Avatar asked Nov 20 '25 11:11

Suha Alhabaj


1 Answers

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

like image 129
NikolaiDante Avatar answered Nov 23 '25 03:11

NikolaiDante