无法加载文件或程序集'Newtonsoft.Json,Version = 7.0.0.0

Mid*_*ali 17 c# asp.net asp.net-mvc json.net nuget

我正面临下面的错误

无法加载文件或程序集"Newtonsoft.Json,Version = 7.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed"或其中一个依赖项.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)

我可以在Web.config中看到下面的内容

   <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

所以我改成了

   <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.1.0" />
      </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

在packeges.config中,我可以看到以下条目

但我仍面临同样的问题.请帮忙

eko*_*nov 39

很多事情都可能出错,而且这条错误信息告诉你什么.

但我仍面临同样的问题.

也许最简单的方法是尝试重新安装软件包.

转到工具> NuGet包管理器并选择包管理器控制台.执行以下两个命令:

uninstall-package newtonsoft.json -force
install-package newtonsoft.json
Run Code Online (Sandbox Code Playgroud)

如果在执行此操作后仍然出现错误,那么最终对我有用的是我从.config文件中删除了Json.Net的部分.如果不存在,重新安装会将其恢复,显然您需要将其删除.直到包装本身有一个正常的解决方案,我担心这个手动步骤是必须的.在包管理器控制台中再次执行:

Update-Package –reinstall Newtonsoft.Json
Run Code Online (Sandbox Code Playgroud)

另请查看解决方案中的.Net版本项目.

这是卸载项目的Microsoft解决方案.


小智 6

我遇到过同样的问题。我按照 ekostadinov 的强制卸载/重新安装步骤进行操作,但需要添加一个额外步骤:

我正在将解决方案升级到 Framework 4.5.2。我的旧 Web.Config 文件在配置标记中有一个命名空间。

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
Run Code Online (Sandbox Code Playgroud)

我更新为:

<configuration>
Run Code Online (Sandbox Code Playgroud)

然后,bingingRedirect 应该适用于您使用的任何版本的 NewtonSoft:

<runtime xmlns="">
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
  </dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)