posted @ Friday, July 29, 2005 11:44 AM
As some of you are aware, I have been working on a UITypeEditor for a custom designer in Enterprise Library. This designer will support Inversion of Control (IoC) Containers for Enterprise Library. Part of the UITypeEditor allows selecting of an assembly and class, be it installed in the GAC or a private assembly. I was running into an issue when I would load a private assembly and attempt to get it collection of types. I was using the static Assembly.LoadFrom method which worked well, except when I called GetTypes(), a ReflectionTypeLoadException exception was thrown. ReflectionTypeLoadException contains a property called LoaderExceptions, which contains a collection of exceptions thrown by the class loader. Each one of these exceptions pointed to another assembly that my main assembly referenced as a dependency.
The problem was these assemblies were all within the same directory as the loaded assembly. According to the probing rules defined within MSDN, based on the directory path provided by the loaded assembly, this is provided as a hint to the location of the referenced assemblies. Unfortunately, this was not working. The solution I found was a method called AppendPrivatePath, which is a method of an AppDomain to tell the assembly resolver where to probe for private assemblies.