引用.NET Standard项目时,NET Framework项目无法加载程序集

时间:2019-01-31 11:46:25

标签: c# .net-core .net-standard

我有一个.NET Framework Web项目,它引用了.NET Standard类库。

运行该应用程序时,我得到:

"Could not load file or assembly 'System.Net.NameResolution, Version=4.0.0.0"

所以我将System.Net.NameResolution 4.3.0 nuget包添加到了这两个项目中。

我不能使用软件包4.0.0,因为这将被降级,因此我向.NET Framework项目添加了绑定重定向:

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

应用程序现在确认了我的重定向,但仍然出现相同的错误:

Could not load file or assembly 'System.Net.NameResolution, Version=4.0.0.0

Calling assembly : EnyimMemcachedCore, Version=1.1.1.11, Culture=neutral, PublicKeyToken=null.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Source\myapp\src\Web\web.config
LOG: Using host configuration file: C:\Users\fraserb\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.0.1.0.
LOG: Post-policy reference: System.Net.NameResolution, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/31e1be3d/fde97fa5/System.Net.NameResolution.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/31e1be3d/fde97fa5/System.Net.NameResolution/System.Net.NameResolution.DLL.
LOG: Attempting download of new URL file:///C:/Source/myapp/src/Web/bin/System.Net.NameResolution.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我哪里出错了?

1 个答案:

答案 0 :(得分:0)

结果表明绑定重定向newVersion应该以4.0.2.0为目标,而不是4.0.1.0,并且此后一切都成功加载。

(我仔细检查了正在加载的DLL的版本后才意识到是4.0.2.0-您可以在Assembly Explorer中查看)