【问题标题】:NET Framework project can't load assembly when referencing .NET Standard projectNET Framework 项目在引用 .NET Standard 项目时无法加载程序集
【发布时间】:2019-01-31 11:46:24
【问题描述】:

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

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

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

我哪里出错了?

【问题讨论】:

  • 您是否在将代码从一个 .NET Framework 升级到下一级或重命名示例项目以创建新项目后收到此错误?如果是这种情况,那么您必须检查项目的所有引用并相应地更新这些位置。 (我遇到了同样的问题并以这种方式解决)。
  • 微软严重搞砸了语义版本控制,但它确实是 4.0.1.0。最明显的解释是您实际上已将 4.0.0.0 部署到您的构建目录中。您首先需要找出为什么需要此绑定重定向。将构建详细程度提高到详细信息,以便查看版本冲突。

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


【解决方案1】:

原来绑定重定向 newVersion 应该针对 4.0.2.0 而不是 4.0.1.0,然后一切都成功加载。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    相关资源
    最近更新 更多