我得到了错误

fileloadexception:无法加载文件或程序集 “Newtonsoft。Json,版本=4.5.0.0,文化=中性, PublicKeyToken=30ad4fe6b2a6aeed'或其依赖项之一。的 定位程序集的清单定义与该程序集不匹配 参考。(异常来自HRESULT: 0x80131040)

用于我的CI构建

我尝试过的解决方案

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
        culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

它也没有起作用


当前回答

如果您在同一解决方案中使用多个项目 和另一个的图书馆 检查是否所有项目都有相同版本的Newtonsoft。Json

其他回答

通过nuget重新安装newtonsoft包不适合我。 我必须手动调用JsonConvert。反序列化对象以绕过此问题

我改变了

HttpResponseMessage response = await client.GetAsync(url));
response.EnsureSuccessStatusCode();
MyObject data = await response.Content.ReadAsAsync<MyObject>();

For

HttpResponseMessage response = await client.GetAsync(url));
response.EnsureSuccessStatusCode();
string jsonStr = await response.Content.ReadAsStringAsync();
MyObject data = JsonConvert.DeserializeObject<MyObject>(jsonStr);

你应该更新网页。配置文件在服务器。 当nuget安装NewtonSoft更新这个文件,包括这个代码

<runtime>
<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="6.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

关于这个开放性话题,还有一个建议。运行“分析”后出现错误:项目设置中发生了更改。问题是:

项目/设置/构建/平台目标

显示“任意CPU”。

设置回x86(或者在您的情况下可能是x64)解决了这个问题。

移除牛顿软。Json程序集从项目引用并再次添加它。您可能不小心删除或替换了dll。

右键单击您的项目选择管理Nuget包,在搜索框中输入newtonsoft并安装最新版本。然后运行你的应用