c# - 由于 System.Net.Http.Formatting.dll 将 Newtonsoft.Json 6.0 升级到 8.0 时出现问题

标签 c# asp.net-web-api json.net nuget assembly-binding-redirect

我想将 Newtonsoft.Json dll 从版本 6.0.0.0 更新到版本 8.0.0.0。我还引用了 System.Net.Http.Formatting.dll 版本 5.2.3.0。它在内部引用 Newtonsoft.Json dll 版本 6.0.0.0。 enter image description here

因此我收到以下错误: System.IO.FileNotFoundException:无法加载文件或程序集“Newtonsoft.Json,Version=6.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。系统找不到指定的文件。

尝试了程序集绑定(bind)并在 app.config 中添加到下面

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="8.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

仍然面临同样的问题。

最佳答案

根据 Nuget Gallery 页面,“System.Net.Http.Formatting”( link ) 不依赖于“Newtonsoft.JSON”。请查看随附的屏幕截图/链接。

enter image description here

我建议重新安装软件包来解决错误:

Update-Package -reinstall -Project 项目名称

关于c# - 由于 System.Net.Http.Formatting.dll 将 Newtonsoft.Json 6.0 升级到 8.0 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61114416/

相关文章:

c# - 使用 JSON.NET 序列化时如何将属性从接口(interface)继承到对象

c# - WPF中如何获取webbrowser控件输入框的值?

asp.net-web-api - 最大扩展深度,带有最新的Web API和 Breeze

c# - Web Api2 和 protected setter ?

c# - 在 ASP.NET Core 中手动绑定(bind)表单数据

c# - Newtonsoft JSON.net 反序列化错误,其中 JSON 中的字段更改顺序

c# - 二进制搜索算法出现错误 - 使用未分配的局部变量

C#:将int[]转换为字符串的最有效方法

c# - C# 中的 Guice 等价物

c# - 如何通过引用同一 JSON 中的另一个键来获取键的值?另外如何将字符串添加到 uri 末尾?