2010-10-21 20 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

回答

相關問題