Suzanne Cook is a Microsoft developer who works on the assembly binding code within the .NET Framework. She writes some fantastic blogs, right up there with Chris Brumme (though thankfully not as long!). Fumiaki agrees that her content is top quality and that she's prepared to go out of her way to help solve problem, including replying to email on a Sunday night.
In a code review with Mark White from MCS last week we were looking at some code I'd written to dynamically load an assembly. In the XP spirit of 'do the simplest thing that works' I had used Assembly.LoadWithPartialName to load in my assembly since I was working on a development version that wasn't strong named or signed. However this is a bad idea because as Suzanne says, it's the pathway back to DLL Hell. As she says:
Assembly.LoadWithPartialName() ... uses partial binding. ... A partial bind is when only part of the assembly display name is given when loading an assembly. ... First, it calls Assembly.Load(). But, if that fails to find the assembly, it will return the latest version of that assembly available in the GAC.
So, in the end I changed to use Activator.CreateInstance. This works with partial binding for now until I strong name the assembly when I can use the full assembly display name. Here's a sketch of the code (minus the error handling):
// Get the type from the config file value
Type remoteAssembly = System.Type.GetType(remoteAssemblyTypeFromConfiigFile);
string assembly = remoteAssembly.Assembly.ToString();
string typeReference = remoteAssembly.FullName;
// Get an object handle to this type
ObjectHandle wrapper = Activator.CreateInstance(assembly, typeReference);
// Unwrape the object handle into the interface we need
IRemoteInterface remote = (IRemoteInterface)wrapper.Unwrap();