views:

23

answers:

1

I've spent an hour debugging this, and I finally eliminated the PEBCAK issue.

I have an internationalized application. A key part of the application uses reflection to load types from configured sources. So in configuration, there's an entry like this:

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

The application loads the component with this code:

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

Which failed miserably when I signed the code. Here's the output from the fusion log viewer:

*** 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).

The PEBCAK was that I spent an hour trying to figure out if the satellite assemblies in multiple cultures were the problem.

No, the problem is, if you specify 2.0.0.0 as the version (see the config snippet above), and your assembly gets a debugging version of 2.0.3946.17829, it's a different version number. The solution was to change the config to this:

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

So my question: I thought you could specify a version to load, and the CLR would load any higher version. Why is this not the case? What'd I miss?

A: 

You can do this, however you have to explicitly allow the redirection to a different version. Details here: MSDN: Redirecting Assembly Versions.

Chris Shaffer