【问题标题】:Be careful with version numbers for loading signed assemblies注意加载签名程序集的版本号
【发布时间】:2010-10-21 16:03:15
【问题描述】:

我花了一个小时调试这个,我终于消除了 PEBCAK 问题。

我有一个国际化的应用程序。应用程序的一个关键部分使用反射从配置的源加载类型。所以在配置中,有这样一个入口:

<component type="Application.Component" assembly="Application, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef"/>

应用程序使用以下代码加载组件:

var assembly = Assembly.Load(assemblyName);
var rawComponent = assembly.CreateInstance(typeName, false, BindingFlags.CreateInstance, null, instanceParams, CultureInfo.CurrentUICulture, null);

当我签署代码时失败了。这是融合日志查看器的输出:

*** Assembly Binder Log Entry  (2010-10-21 @ 11:10:52) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\JetBrains\ReSharper\v5.1\Bin\JetBrains.ReSharper.TaskRunner.CLR4.MSIL.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = DOMAIN\user
LOG: DisplayName = Application.resources, Version=2.0.3946.17829, Culture=es-ES, PublicKeyToken=0123456789abcdef
 (Fully-specified)
LOG: Appbase = file:///C:/Source/Application/UnitTests/bin
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\user\AppData\Local\Temp\w3gjhpl2.blr
LOG: AppName = Application.UnitTests
Calling assembly : Application, Version=2.0.3946.17829, Culture=neutral, PublicKeyToken=0123456789abcdef.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Source\Application\UnitTests\bin\Application.UnitTests.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Application.resources, Version=2.0.3946.17829, Culture=es-ES, PublicKeyToken=0123456789abcdef
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

PEBCAK 是我花了一个小时试图弄清楚多种文化中的附属程序集是否是问题所在。

不,问题是,如果您指定 2.0.0.0 作为版本(请参阅上面的配置 sn-p),并且您的程序集获得了 2.0.3946.17829 的调试版本,那么它是一个不同的版本号。解决方案是将配置更改为:

<component type="Application.Component" assembly="Application, Version=2.0, Culture=neutral, PublicKeyToken=0123456789abcdef"/>

所以我的问题是:我认为您可以指定要加载的版本,CLR 会加载任何更高版本。为什么不是这样?我错过了什么?

【问题讨论】:

  • “CLR 会加载任何更高版本” - 为什么?

标签: c# .net reflection internationalization assembly-signing


【解决方案1】:

您可以这样做,但是您必须明确允许重定向到不同的版本。详情在这里:MSDN: Redirecting Assembly Versions.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 2011-05-25
    • 2010-09-08
    相关资源
    最近更新 更多