我得到了错误

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>

它也没有起作用


当前回答

我修复了添加这个绑定重定向到我的.config文件的问题:

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

错误消息抱怨找不到版本4.5.0.0,当前版本的Newtonsoft。Json是6.0.0.0,所以重定向应该从4.5到6.0,而不是相反

其他回答

致所有使用牛顿软体有问题的人。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标记将被忽略。

我写了一个程序来自动修复这个问题。它将确保您的程序能够使用硬盘驱动器上目标程序集的最新版本,而不仅仅是依赖库需要的版本。

https://github.com/BackTrak/DependencyFixup/releases/tag/1.0.0.0

无需再猜测,它将自动为您修复所有清单引用问题。

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

我犯了一个错误,为。net 4.5添加了一个NewtonSoft .dll文件。

我的主要项目是4.5,但当我向我的解决方案添加一个额外的项目时,它奇怪地将它添加为。net 2.0项目……当我试图使用NewtonSoft的4.5 dll时,我得到了这个“NewtonSoft”。Json cannot 't be found”错误。

解决方案(当然)是将这个新项目从。net 2.0改为4.5。

uninstall-package newtonsoft.json -force
install-package newtonsoft.json

对我来说是这样的:)