我得到了错误

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>

它也没有起作用


当前回答

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

其他回答

对我来说,问题是一个贬值版的Newtonsoft.Json。重新安装也无济于事。

在Visual Studio中,进入工具->管理NuGet包。选择更新。搜索Newtonsoft。单击Update安装最新版本。

你可以从引用中的属性中找到你的库的安装版本。对于我的情况,我安装了8.0.0.0。错误提示无法加载文件或程序集'Newtonsoft。Json,版本=6.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed'或其依赖项之一。

所以我必须在web.config中手动添加以下内容

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

通过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);

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

我也为此挣扎了一天左右,尝试了所有的解决方案。 帮助我的是检查app.config中的大写字母。我有PublicKeyToken,而不是PublicKeyToken,改变后突然工作了。