ReflectionTypeLoadException diagnosis?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm trying to load a list of types from a dynamically
loaded assembly, e.g:

Assembly a = Assembly.LoadFrom(path);
a.ModuleResolve += new ModuleResolveEventHandler
(OnAssemblyModuleResolve);
types = a.GetTypes();

ReflectionTypeLoadException gets thrown on the second
line:
System.Reflection.ReflectionTypeLoadException: One or
more of the types in the assembly unable to load.

I'm trying to work out exactly why. If I listen to the
ModuleResolve assembly event as well as the current
AppDomain's AssemblyResolve and TypeResolve events,
nothing fires - I would of expected one of them to. The
exception instance isn't very helpful either, it just
lists the types that *were* loaded, not the one(s) that
caused the problem. I've tried using the binding log
viewer, but it reports nothing, and I've also tried using
the Assembly.LoadFile() method instead of LoadFrom.

The current AppDomain's RelSearchPath and BasePath both
seem to be right (RelSearchPath includes the directory of
the assembly being loaded, and BasePath includes library
assemblies that the loaded assembly requires). No
assemblies (besides the FX) are in the GAC, nor do I want
them to be.

How do I work out what's going wrong here?? Why don't the
Module/Type resolve failure events fire?
 
I am experiencing a similar issue that doesn't seem to be addressed in
any of the related posts to this newsgroup. I am guessing that your
exception is being thrown on the first line (the "LoadFrom")- this is
identical to the issue I am having trying to load types dynamically
from an assembly DLL file.

When I am in Visual Studio .NET, I have no problem clicking
"Project...Add Reference...", then browsing to the DLL and adding a
reference to my project. This adds all types from the assembly to my
project as expected, and I can verify this by looking at the object
viewer.

I think there is a difference between the way Assembly.LoadFrom(...)
works and the mechanism being used in Visual Studio .NET. The best I
can gather is that an assembly with DLL dependencies cannot be loaded
because those dependency DLLs cannot be found. Maybe
Assembly.LoadFrom(...) doesn't use the system path, where Visual
Studio .NET searches the system path or registered components to find
all the dependencies.

If you have DLL dependencies, try copying them to the same directory
as your assembly DLL/EXE and rerunning the code snippet- this may
solve your problem. If anyone from Microsoft is reading this, can you
attempt to actually respond to this issue and not ignore it? Is this a
problem with the Assembly class or what? I haven't seen a satisfactory
solution posted yet and my experience is Microsoft Inc is slow to
admit to mistakes or errors in their codebase.
 
Back
Top