简体   繁体   English

无法使用 Google.Apis 加载文件或程序集 'Newtonsoft.Json,版本 = 12.0.0.0 问题。*

[英]Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 issue using Google.Apis.*

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.无法加载文件或程序集“Newtonsoft.Json,版本=12.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自 HRESULT 的异常:0x80131040)

Doing my head in trying to find this reference.努力寻找这个参考。 I am running a .NET Framework v4.5 project, and then importing the DLL into an aspx page.我正在运行 .NET Framework v4.5 项目,然后将 DLL 导入 aspx 页面。

The DLL contains a class used to connect to the Google APIs - specifically for the Google Calendar. DLL 包含一个 class 用于连接到 Google API - 专门用于 Google 日历。

I've tried removing all the NuGet references and re-installing.我尝试删除所有 NuGet 引用并重新安装。 I've ensured they are all updated to the latest stable version.我已经确保它们都更新到最新的稳定版本。 The Newton.JSON library is specifically set to v13.0.1. Newton.JSON 库专门设置为 v13.0.1。

My packages.config file is as follows:我的 packages.config 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Google.Apis" version="1.51.0" targetFramework="net45" />
  <package id="Google.Apis.Auth" version="1.51.0" targetFramework="net45" />
  <package id="Google.Apis.Calendar.v3" version="1.51.0.2312" targetFramework="net45" />
  <package id="Google.Apis.Core" version="1.51.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
  <package id="System.Net.Http" version="4.0.0" targetFramework="net45" />
</packages>

I've seen others suggesting updating the web.config file in the following folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config I have no idea why though.我看到其他人建议更新以下文件夹中的 web.config 文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 我不知道为什么。 There are no references to the Newton.JSON library in there.那里没有对 Newton.JSON 库的引用。

Where to next?下一步去哪里?

EDIT: I have resolved this as recommended below by editing the web.config of the website to point old references to the new one, however I now receive the following error:编辑:我已通过编辑网站的 web.config 以将旧引用指向新引用,按照以下建议解决了此问题,但是我现在收到以下错误:

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'无法从程序集“mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089”加载类型“System.Reflection.IntrospectionExtensions”

This is usually bequase one of the other packages references Newton.JSON version 12.0.0.0 directly.(In this case probably the google apis packages)这通常是因为其他软件包之一直接引用Newton.JSON版本 12.0.0.0。(在这种情况下可能是 google apis 软件包)
As you add 13.0.1 to you project the other packages cant find the reference.当您将 13.0.1 添加到您的项目时,其他包无法找到参考。
You can add the following bit to the config:您可以将以下位添加到配置中:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">     
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    <loadFromRemoteSources enabled="true" />
  </runtime>

What this does is, when you code or one of the packages references a version of Newtonsoft.Json between version 0 and 13 it will now reference version 13它的作用是,当您编码或其中一个包引用版本 0 和 13 之间的Newtonsoft.Json版本时,它现在将引用版本 13

Look into the.csproj file it should also been updated v13查看 .csproj 文件,它也应该更新为 v13

sample样本

 <ItemGroup>
    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System.Net.Http" />
  </ItemGroup>

and make sure the dependent Assembly in web config also has been updated并确保 web 配置中的依赖程序集也已更新

Sample:样本:

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

I had this same problem and found it important to note something else.我遇到了同样的问题,发现重要的是要注意其他事情。 Connor's answer was correct but my users still had this issue.康纳的回答是正确的,但我的用户仍然有这个问题。 My app is a WPF application whereas even though I had this change in my app.config they did not have it in theirs.我的应用程序是 WPF 应用程序,而即使我的 app.config 中有此更改,他们的应用程序中也没有。 It took a couple hours to track down while it was failing for them.当他们失败时,他们花了几个小时才找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 12.0.0.0? - Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0? 无法加载文件或程序集“NewtonSoft.Json,版本=12.0.0.0” - Could not load file or assembly 'NewtonSoft.Json, Version=12.0.0.0' System.IO.FileNotFoundException: &#39;无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 12.0.0.0, - System.IO.FileNotFoundException: 'Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, 在容器 dotnet 核心容器中运行时,无法加载文件或程序集“Newtonsoft.Json,版本 = 12.0.0.0” - Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 when running in container dotnet core container Newtonsoft.Json版本8.0.2无法加载文件或程序集错误 - Newtonsoft.Json version 8.0.2 Could not load file or assembly Error 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 10.0.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 7.0.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0 无法加载文件或程序集“Newtonsoft.Json”版本=11.0.0.0 - Could not load file or assembly 'Newtonsoft.Json' Version=11.0.0.0 无法加载文件或程序集'Newtonsoft.Json,版本 = 3.5.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0 无法加载文件或程序集Newtonsoft.json版本6.0.0.0 - Could not load file or assembly Newtonsoft.json Version 6.0.0.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM