繁体   English   中英

为什么 Autofac.Integration.WebApi.Owin 5.0.0 在 TargetFramework v4.7.1 上引用 System.Net.Http 4.2.0?

[英]Why is Autofac.Integration.WebApi.Owin 5.0.0 referencing System.Net.Http 4.2.0 on TargetFramework v4.7.1?

我有一个带有 TargetFrameworkVersion v4.7.1 的程序集,它引用了 Autofac.Integration.WebApi.Owin 5.0.0。

在编译过程中,我收到一条警告,说warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. 在仅安装了 .NET Framework 4.7.1 的服务器上运行我的应用程序,我收到以下运行时异常

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Owin.AutofacWebApiAppBuilderExtensions.UseAutofacWebApi(IAppBuilder app, HttpConfiguration configuration)

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\xx\yyServer\yyServer.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/xx/yy/Server/
LOG: Initial PrivatePath = NULL
Calling assembly : Autofac.Integration.WebApi.Owin, Version=5.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.

从 dotPeek,我可以看到有关程序集的以下信息

Autofac.Integration.WebApi, 5.0.0.0, msil, .Net Framework v4.6.1, Debug
   References:
     - System.Net.Http (4.2.0.0)
Autofac.Integration.WebApi.Owin, 5.0.0.0, msil, .Net Framework v4.6.1, Debug
   References:
     - System.Net.Http (4.2.0.0)
My.Assembly, 1.0.0.0, msil, .Net Framework v4.7.1, Debug
   References:
     - System.Net.Http (4.0.0.0)

如果我创建一个面向 .NET Framework v.4.6.1-4.7.1 的新的空项目,System.Net.Http 引用声称版本为 4.0.0.0。 如果我将项目提升到 4.7.1,System.Net.Http 引用会显示 4.2.0.0。 查看 System.Net.Http 的 nuget 包,没有 4.2.0 版本。 在实际项目中使用 .NET Framework 4.7.2 可能会起作用,但我目前无法更新到新的 TargetFramework。

将以下程序集重定向添加到 app.config 似乎可以在运行时解决这个特定问题,但是我不确定我对重定向框架程序集有多满意,以及可能带来的其他后果。 编译时警告仍然存在。

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

为什么 Autofac 程序集引用版本 4.2.0? 包裹有问题吗? 有没有比使用程序集重定向更好的方法来解决这个问题?

稍等片刻,如果您system.net.http 4.2.0.0上搜索system.net.http 4.2.0.0您会发现这是很多包的问题,​​从DocumentDbSystem.Collections.Immutable 它显然源于一个工具问题,其中使用 VS 2017 构建程序集(这是 System.Net.Http 4.2.0.0 的来源)并且在构建时该版本在那里,但在运行时该项目不是用相同的工具集和程序集丢失。

如您所见,短期解决方法是程序集绑定重定向。

对于长期解决方法,Autofac 包需要更新。 我已经代表你提交了一个问题。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM