【问题标题】:Library version conflicts in .NET: System.Net.Http.NET 中的库版本冲突:System.Net.Http
【发布时间】:2017-11-04 02:42:26
【问题描述】:

我正在尝试使用 NuGet 包管理器控制台将更改部署到数据库。当我发出Update-Database 命令时,它失败并显示错误消息:

Could not load file or assembly 'System.Net.Http, Version=4.1.1.1,
  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
  dependencies. The system cannot find the file specified.

我的项目以 .NET 4.5.2 为目标,据我所知,它在版本 4.0.0.0 中提供了 System.Net.Http。因此,被指控的库不在二进制输出目录中。当我下载 4.1.1.1 版本(NuGet 包版本 4.3.2)并将其与我的 DLL 一起复制到二进制输出目录中时,我收到另一条错误消息:

Loading this assembly would produce a different grant set from other
  instances. (Exception from HRESULT: 0x80131401)

在这两种情况下,异常都是System.IO.FileLoadException,并在Microsoft.Rest.ServiceClient'1.CreateRootHandler() 中抛出。我检查了该函数的源代码,它实际上引用了 .NET 4.5 和 System.Net.Http:

  protected static HttpClientHandler CreateRootHandler()
  {
    // Create our root handler
#if NET45
    return new WebRequestHandler();
#else
    return new HttpClientHandler();
#endif
  }

但是,我无法找到System.Net.Http 的确切版本号。最后,我使用 ILSpy 检查了Microsoft.Rest.ClientRuntime,它似乎依赖于版本4.0.0.0 中的System.Net.Http

我还尝试删除对System.Net.Http 的所有引用并安装最新的 NuGet (4.3.2)。这会导致缺少方法的后续错误:

Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(
  AuthenticationCallback, System.Net.Http.DelegatingHandler[])'.

Method not found: 'Void Microsoft.Rest.ServiceClient`1..ctor(
  System.Net.Http.DelegatingHandler[])'.

我通过将相应的 NuGet 中的正确 DLL 复制到部署目录中解决了这个问题。这最终导致:

Loading this assembly would produce a different grant set from other
  instances. (Exception from HRESULT: 0x80131401)

我错过了什么?

【问题讨论】:

  • 你能解决这个问题吗?我现在遇到了同样的问题,我已经尝试了很多我在网上找到的潜在解决方案,但似乎没有一个有效......
  • 不,但我使用了实体框架附带的 migrate.exe,它可以畅通地将更改部署到数据库。我认为visual studio仍然被阻止(即包管理器控制台)但我根本不在乎。

标签: .net nuget


【解决方案1】:

在这里找到库纳尔的答案后:

MongoDB client throws a FileNotFoundException in mscorlib

为我工作,我尝试更改 System.Net.Http 的版本号。我安装了针对 net462 的 System.Net.Http 4.3.3 版,这对我有用:

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    相关资源
    最近更新 更多