其他分享
首页 > 其他分享> > 修复json.net(Newtonsoft.Json)运行时文件加载异常

修复json.net(Newtonsoft.Json)运行时文件加载异常

作者:互联网

每次运行项目时,都会收到以下异常:

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)

我尝试了几乎可以在网上找到的所有解决方案.

我的packages.config文件:

<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>

我什至使用以下命令来更新/重新安装json.net:

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

我还能尝试什么?

解决方法:

更改绑定重定向newVersion和oldVersion以匹配您尝试使用的Json.net版本:

  <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是框架版本,而不是Json.net版本

标签:json-net,fileloadexception,c,net
来源: https://codeday.me/bug/20191119/2032942.html