【问题标题】:Dependent assembly resolution succeeds even with the wrong version number即使版本号错误,依赖程序集解析也会成功
【发布时间】:2014-12-03 14:08:49
【问题描述】:

我一直在寻找我在程序集解析中检测到的奇怪行为的答案,但无济于事。我知道 CLR 将程序集的引用记录到其元数据(清单)中。它记录名称、版本号、公钥令牌和语言环境。在加载程序集时,每个引用的程序集都会被探测和加载。这个探针是版本敏感的,或者换句话说,应该定位和加载构建中使用的相同版本,而不是任何其他版本。如果程序集被签名,公钥也会起作用。

问题是在我为测试创建的虚拟应用程序中,这条规则被打破了!我已经搜索过 SO 和 google 并且答案不正确。请不要给我以下原因,解决方法:

  • “特定版本”设置为 False:这仅在编译时为 true,与运行时无关。
  • 此外,没有应用程序/计算机配置集。

在我的测试设置中,我的项目 A 引用了项目 B。在对每个项目 B 进行版本控制后,我只构建自己而不是 A。现在我将具有更改版本的新 B.DLL 复制到 A 的工作目录中并运行 A 。 有用 !!我预计它会崩溃。

Fuselogvw.exe 的输出应该是不言自明的。在日志中提到程序集应该寻找版本 9,但版本 8 已定位并加载!注意这一行:

LOG:程序集名称为:dllProj,版本=1.1.10.8,文化=中性, PublicKeyToken=null

*** Assembly Binder Log Entry  (10/8/2014 @ 2:34:51 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable  C:\...\Documents\Visual Studio 2013\Projects\test1\test1\bin\Release\test1.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = ...
LOG: DisplayName = dllProj, Version=1.1.10.9, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/.../Documents/Visual Studio 2013/Projects/test1/test1/bin/Release/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : test1, Version=1.1.1.1, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\...\Documents\Visual Studio 2013\Projects\test1\test1\bin\Release\test1.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.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:/.../Documents/Visual Studio 2013/Projects/test1/test1/bin/Release/dllProj.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\...\Documents\Visual Studio 2013\Projects\test1\test1\bin\Release\dllProj.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: dllProj, Version=1.1.10.8, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\...\Documents\Visual Studio 2013\Projects\test1\test1\bin\Release\dllProj.dll.
LOG: Assembly is loaded in default load context.

【问题讨论】:

  • 您是否尝试过更改版本号的第一个或第二个元素(主要/次要)?
  • 我很确定出版商政策可以应用于主要、次要但汇编决议与完全匹配有关。但是,在我看来,“私有程序集”可能没有强制执行版本控制?

标签: c# .net clr .net-assembly assemblyresolve


【解决方案1】:

MSDN 中,几乎在main page about assembly binding 的末尾有一个小字:

没有强名称的程序集没有版本检查,也没有 运行时是否在全局程序集缓存中检查程序集 没有强名称。

有很多因素会影响程序集绑定,但在您的这个特定示例中,此行为是由 B 程序集未使用强名称引用这一事实定义的。

【讨论】:

  • 正确答案 :) 我很高兴当时没有人回答这个问题。
猜你喜欢
  • 1970-01-01
  • 2014-02-21
  • 2021-10-13
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
  • 2015-01-20
  • 2018-08-17
相关资源
最近更新 更多