无法加载文件或程序集 'Newtonsoft.Json,版本=12.0.0.0 使用 Google.Apis 问题。*
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. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
竭尽全力寻找此参考资料。我是运行一个.NET Framework v4.5项目,然后将DLL导入到一个aspx页面中
DLL 包含一个 class 用于连接到 Google API - 专门用于 Google 日历。
我已尝试删除所有 NuGet 引用并重新安装。我确保它们都更新到最新的稳定版本。 Newton.JSON库专门设置为v13.0.1.
我的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>
我看到其他人建议更新以下文件夹中的 web.config 文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 我不知道为什么尽管。那里没有对 Newton.JSON 库的引用。
下一步去哪里?
编辑:我已经按照下面的建议解决了这个问题,方法是编辑网站的 web.config 以将旧引用指向新引用,但是我现在收到以下错误:
Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
查看 .csproj 文件
它也应该更新为 v13
样本
<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>
并确保 web 配置中的依赖程序集也已更新
样本:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
这通常是因为引用了其他软件包之一 Newton.JSON
版本 12.0.0.0
直接。(在这种情况下可能是 google api 包)
当您将 13.0.1 添加到您的项目时,其他包找不到引用。
您可以将以下位添加到配置中:
<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>
这样做的目的是,当您编写代码或其中一个包引用版本 0 和 13 之间的 Newtonsoft.Json
版本时,它现在将引用版本 13
我遇到了同样的问题,发现注意其他事项很重要。 Connor 的回答是正确的,但我的用户仍然遇到这个问题。我的应用程序是一个 WPF 应用程序,而即使我在 app.config 中进行了此更改,他们的应用程序中也没有。他们花了几个小时才找到失败。
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)
竭尽全力寻找此参考资料。我是运行一个.NET Framework v4.5项目,然后将DLL导入到一个aspx页面中
DLL 包含一个 class 用于连接到 Google API - 专门用于 Google 日历。
我已尝试删除所有 NuGet 引用并重新安装。我确保它们都更新到最新的稳定版本。 Newton.JSON库专门设置为v13.0.1.
我的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>
我看到其他人建议更新以下文件夹中的 web.config 文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 我不知道为什么尽管。那里没有对 Newton.JSON 库的引用。
下一步去哪里?
编辑:我已经按照下面的建议解决了这个问题,方法是编辑网站的 web.config 以将旧引用指向新引用,但是我现在收到以下错误:
Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
查看 .csproj 文件 它也应该更新为 v13
样本
<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>
并确保 web 配置中的依赖程序集也已更新
样本:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
这通常是因为引用了其他软件包之一 Newton.JSON
版本 12.0.0.0
直接。(在这种情况下可能是 google api 包)
当您将 13.0.1 添加到您的项目时,其他包找不到引用。
您可以将以下位添加到配置中:
<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>
这样做的目的是,当您编写代码或其中一个包引用版本 0 和 13 之间的 Newtonsoft.Json
版本时,它现在将引用版本 13
我遇到了同样的问题,发现注意其他事项很重要。 Connor 的回答是正确的,但我的用户仍然遇到这个问题。我的应用程序是一个 WPF 应用程序,而即使我在 app.config 中进行了此更改,他们的应用程序中也没有。他们花了几个小时才找到失败。