我得到了错误

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>

它也没有起作用


当前回答

你可以从引用中的属性中找到你的库的安装版本。对于我的情况,我安装了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>

其他回答

我花了几天时间试图解决这个令人沮丧的问题。我几乎试遍了网上能找到的所有方法。最后我发现这个错误可能是由一个解决方案中不同的目标. net项目版本(4.5和4.5.1)引起的(就像我的情况一样)。下面的步骤帮我解决了这个问题:

仔细检查解决方案中每个项目的. net版本。只需右键单击项目,然后进入属性。

If possible set the same .Net version for all projects. If not at least try to change the Startup project one (for me this was the one causing the issues). Remove all Newtonsoft.Json packs from the solution. uninstall-package newtonsoft.json -force Update all Newtonsoft.Json versions in all packages.config files, like so <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" /> Reinstall Newtonsoft.Json from "Package Manager Console" with: install-package newtonsoft.json Rebuild the solution

(可选)7。如果更改了Startup项目,请再次返回

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

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

除了这里的许多答案之外,我发现了一些东西,因此添加了它。第一点,确保dll没有从GAC引用。除此之外,

在添加/更改Newtonsoft的dll时。Json,有时*。项目的Csproj不会被更改,否则json DLL的更改版本将不会反映在解决方案的Csproj中。

在notepad++中打开项目,搜索Newtonsoft。并显式地将Json从旧版本重命名为新版本。现在切换回VS后,解决方案/项目将重新加载所需的Newtonsoft版本。JSON dll。

关闭解决方案。

打开包。Config和*。用csproj文本编辑器删除任意一行都有Newtonsoft。Json

Ex:

<Reference Include="Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
      <Private>True</Private>
</Reference>

Or

<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />

再次打开解决方案并重新安装Newtonsoft。Json由安装包Newtonsoft。Json

这对我很管用。

看看Newtonsoft的版本。Json Newtonsoft属性

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