我得到了错误

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>

它也没有起作用


当前回答

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

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

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

其他回答

致所有使用牛顿软体有问题的人。Json v4.5版本尝试在web中使用这个。Config或app.config:

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

重要提示:检查配置文件的配置标记是否没有命名空间属性(如https://stackoverflow.com/a/12011221/150370中建议的那样)。否则,assemblyBinding标记将被忽略。

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

我认为你指向错误的目标,把它改为4.5而不是6.0

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

这应该有用。

updating web.config with the following assembly binding resolved the issue 
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">     
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
                culture="neutral" />
        <bindingRedirect oldVersion="4.5.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

我没有运气的任何解决方案在这里(卸载,重新安装,删除引用,创建bindingRedirects等),我不得不回到旧版本的Newtonsoft。版本5.0.6以前可以工作,所以我尝试了这个版本。我必须在包控制台中输入这两个命令:

uninstall-package newtonsoft。json force

安装包newtonsoft。Json -version "5.0.6"

第一个命令中的-force选项必须强制卸载。与其他程序集的依赖关系阻止在没有它的情况下卸载。