Reputation: 18815
I have a broken Assembly that I want to reflect over, its not broken badly, it just cannot find a referenced assembly, so it does fail a PEVerify. But....Assembly.LoadFrom() will still load it and GetTypes() will throw a ReflectionTypeLoadException, the .LoaderExceptions array shows me what referenced assembly cannot be found. At this point I am roadblocked.
However, the great little tool Reflector is able to go further and actually display the contained types, and handles gracefully the missing reference issue by giving me a pop-up dialog to browse for it. My question is, How after the GetTypes() fails does reflector manage to get the types anyway?
Upvotes: 3
Views: 1378
Reputation: 941
Module.GetTypes()
will throw this same exception. If you catch a ReflectionTypeLoadException
from the Assembly.GetTypes()
call, that exception will have a "Types" property on it of all the types that it could load. The ones that it couldn't will be detailed in a list/array property called LoaderExceptions
.
Upvotes: 4
Reputation: 8781
Not too sure if this will help, but perhaps try getting the the modules first and then the types from there.
Assembly a = Assembly.Load(brockenAssembly);
Module[] mList = a.GetModules();
for (int i = 0; i < mList.length; i++)
{
Module m = a.GetModules()[i];
Type[] tList = m.GetTypes();
}
Hope fully you could get the list of types available in one of the modules.
Upvotes: 0