我得到了错误

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。NET库。要解决这个问题,你应该把它们升级到最新版本。遵循以下步骤:

1-打开解决方案资源管理器 2右键单击解决方案名称 3选择“解决方案管理Nuget包” 从菜单中选择“更新” 5 update JSON。净包

这将解决你的问题。

链接: 无法加载文件或程序集'Newtonsoft。Json,版本=7.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed'或其依赖项之一

其他回答

对于一个最简单的解决方案,你可以设置你的项目文件自动生成绑定重定向:

<PropertyGroup>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection

我也遇到了同样的错误,为此纠结了好几个小时。我有一个使用Newtonsoft的web API项目。json和另一个UnitTest项目的web API项目。单元测试项目也需要Newtonsoft。json参考。但是在添加链接时,我得到了上面的异常。

我最终通过在单元测试项目的app.config中添加以下代码片段来解决这个问题:

<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>

我也有同样的问题。我还用下面的方法解决了这个问题: 进入TOOLS > NuGet包管理器,选择包管理器控制台。最后,执行以下两个命令:)

uninstall-package newtonsoft。json force 安装包newtonsoft.json

答案从2022年开始。 得到类似的异常错误:

Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

解决办法是进入网络。配置文件的项目,并进行以下编辑:

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

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

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