Assembly.Load, Version Numbers and Unsigned Assemblies
Never assume anything, test everything
All these years I assumed that Assembly.Load() would respect version numbers if specified in the FullName string. As I’ve been adding more test coverage to Microsoft.Activities I found that Assembly.Load does not work that way.
Suppose you have an assembly named ActivityLibrary and you deploy V1 but you try to load V2
// This call will succeed and happily load V1 if it finds ActivityLibrary.dll
Assembly.Load("ActivityLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null");
To force Assembly.Load to respect the version number you must sign the assembly
// Try to load V2 this call will fail if it cannot find V2
Assembly.Load("ActivityLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=824701d2ab05d638");
So be careful out there and sign your assemblies.
Comments
- Anonymous
January 12, 2011
Hehe. Quite a shock huh. I think the rationale used to be that unsigned assemblies can be bin edited in any way you see fit (including version) so you could trust what you find there anyway ...