2010-10-21 52 views
3

我花了一个小时来调试这个,最后我终于消除了PEBCAK问题。加载签名程序集的版本号时要小心

我有一个国际化的应用程序。应用程序的关键部分使用反射来从配置的源加载类型。因此,在配置中,有这样一个条目:

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

的应用程序加载组件使用此代码:

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=abcdef 
(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=abcdef. 
=== 
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=abcdef 
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作为版本(请参阅上面的配置代码片段),并且您的程序集获得调试版本2.0.3946.17829,则它是不同的版本号。解决的办法是改变配置,以这样的:

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

所以我的问题:我想你可以指定一个版本加载,和CLR会加载任何更高的版本。为什么不是这种情况?我错过了什么?

+0

“CLR将加载任何更高版本” - 为什么? – bzlm 2010-10-21 17:18:40

回答

相关问题