System.Net.Http 的绑定重定向不起作用 - 为什么?

Binding redirect for System.Net.Http doesn#39;t work - why?(System.Net.Http 的绑定重定向不起作用 - 为什么?)
本文介绍了System.Net.Http 的绑定重定向不起作用 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 NuGet,我正在处理的项目安装了 System.Net.Http 版本 4.3.3.它在 Web.config 文件中有一个绑定重定向,可将其重定向到 4.2.0.0 版本,但出于某种原因,该重定向有效:

The project I'm working on has System.Net.Http version 4.3.3 installed, according to NuGet. It had a binding redirect in the Web.config file to redirect it to version 4.2.0.0, which worked for some reason:

<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>

我将其更改为指向 4.3.3.0,即 NuGet 所说的已安装版本:

I changed it to point to 4.3.3.0 which is the version NuGet says is installed:

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

...但是现在当我尝试调试 ASP.NET 站点时出现此错误:

... but now I get this error when I try to debug the ASP.NET site:

Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Net.Http | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/.../Dev/Src/Web/PortalSite/
LOG: Initial PrivatePath = C:...DevSrcWebPortalSitein
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:...DevSrcWebPortalSiteweb.config
LOG: Using host configuration file: C:...DocumentsIISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../Dev/Src/Web/PortalSite/bin/System.Net.Http.DLL.
LOG: Using application configuration file: C:...DevSrcWebPortalSiteweb.config
LOG: Using host configuration file: C:...DocumentsIISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Redirect found in application configuration file: 4.2.0.0 redirected to 4.3.3.0.
LOG: Post-policy reference: System.Net.Http, Version=4.3.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../Dev/Src/Web/PortalSite/bin/System.Net.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

为了让事情变得更加混乱,该站点的 bin 目录中的 DLL 版本似乎又有所不同:

To make things even more confusing, the DLL version in the bin directory for the site seems to be different again:

PS C:...DevSrcWebPortalSitein> (Get-Item ...inDebugSystem.Net.Http.dll).VersionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
4.6.25908.02 ... 4.6.25908.02     C:...DevSrcWebPortalSiteinSystem.Net.Http.dll

这是怎么回事?重定向以前是如何工作的,为什么现在不能工作?

What's up with this? How did the redirect work before, and why doesn't it work now?

推荐答案

原来我的bin目录下的DLL版本其实是4.2.0.0版本,也就是显然是与 Visual Studio 2017 捆绑在一起的,并且 NuGet 包版本 4.3.3 中分发的版本是 DLL 版本 4.1.1.2,根本没有使用.令人困惑!但这解释了为什么重定向到 DLL 版本 4.2.0.0 有效而重定向到 4.3.0.0 无效.

It turns out that the DLL version in my bin directory was actually version 4.2.0.0, which is apparently bundled with Visual Studio 2017, and the version distributed in NuGet package version 4.3.3 is DLL version 4.1.1.2, which wasn't being used at all. Confusing! But this explains why the redirect to DLL version 4.2.0.0 worked and redirecting to 4.3.0.0 didn't.

这篇关于System.Net.Http 的绑定重定向不起作用 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)