我得到了错误

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 Newtonsoft属性

然后你需要在你的web配置中添加这个版本(在我的例子中是8.0.0.0) 网络配置

其他回答

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>

下面的部分添加到您的web.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>

我也有同样的问题,当我试图创建MassTransit队列时,我得到了异常:

"Exception: System.TypeInitializationException: The type initializer for 'MassTransit.Serialization.JsonMessageSerializer' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

对我有效的解决方案(在花了几天时间恢复了几次提交后):

We had a windows service solution that has .Service project and .XUnitTests project. Both of them were using a common nuget that has dependency on Newtonsoft.Json.dll. There was no explicit reference to Newtonsoft.Json nuget package in both projects (but we were using 'using Newtonsoft.Json;' namespace in our classes), so the common nuget was using version 9 of Newtonsoft.Json by default. As soon as I installed the Newtonsoft.Json nuget in both .Service and .XUnitTests projects, the common nuget package started using the latest v12 Newtonsoft and that fixed my issue.

如果能节省大家宝贵的时间,就贴在这里吧。

在我的案例中,在下载程序集并将引用添加到项目后,我通过在将引用添加到项目之前“解锁”DLL来解决这个问题。

使用Windows资源管理器,浏览到DLL位置,右键单击DLL,然后选择“属性”。您将在其中一个选项卡上找到一个“unblock”按钮,然后您可以添加引用,程序集将正确加载。

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

uninstall-package newtonsoft。json force

安装包newtonsoft。Json -version "5.0.6"

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