【问题标题】:How to fix json.net (Newtonsoft.Json) runtime file load exception如何修复 json.net (Newtonsoft.Json) 运行时文件加载异常
【发布时间】:2016-05-28 07:42:42
【问题描述】:

每次运行项目时都会出现以下异常:

“System.IO.FileLoadException”类型的异常发生在 mscorlib.dll 但未在用户代码中处理 附加信息:无法加载文件或程序集“Newtonsoft.Json,版本=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (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

我还能尝试什么?

【问题讨论】:

  • 我不确定,但也没有用。
  • 我刚刚检查过,Json.NET 8.0.2 typeof(JsonSerializer).Assembly.FullNameVersion=8.0.0.0。所以试一试吧。
  • 另见stackoverflow.com/questions/22685530/…。当然,该答案中的版本号不适合 Json.NET 8.0.2。
  • 您对版本号的看法是正确的,当我尝试重新安装时收到此消息:Successfully added 'Newtonsoft.Json 8.0.2' to Prodb1.但异常仍然会在运行时出现。

标签: c# .net json.net fileloadexception


【解决方案1】:

更改绑定重定向 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的版本

【讨论】:

  • 我还是有异常。这与这条消息有什么关系吗?文件visual studio 2013\Projects\Prodb1\packages\Newtonsoft.Json.8.0.2\tools\install.ps1 无法加载,因为在此系统上禁用了运行脚本。
  • 还有其他信息,还是完全改变了?
  • 您能以mvce 的身份分享您的代码吗?目前我无法在本地重现您的确切场景。
【解决方案2】:

谢谢大家,我找到了问题。当我把它放在 web.config 中时,我没有添加culture="neutral"。

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

【讨论】:

    【解决方案3】:

    我遇到了这个问题,经过仔细检查,我意识到 Newtonsoft 以某种方式被添加了两次

    <dependentAssembly>..</dependentAssembly>
    

    在我的 web.config 文件中。我有版本 8.0 和 9.0 条目。我相信第二个条目是在我从 8.0 更新到 9.0 时创建的。自动创建了一个新条目,但没有删除旧条目。

    【讨论】:

      【解决方案4】:

      我刚刚为我的项目安装了 Nuget 包“Newtonsoft.json”时遇到了同样的问题。然后就解决了

      【讨论】:

        猜你喜欢
        • 2019-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-16
        相关资源
        最近更新 更多