Wednesday, January 12, 2011

Blog Post: 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.

Gina Gershon Ehrinn Cummings Sienna Miller Cindy Taylor Halle Berry

No comments:

Post a Comment