How reflector displays types when Assembly.GetTypes () fails due to lack of assembly reference

I have a broken assembly that I want to conceive, it can’t be broken badly, it just cannot find the link to the assembly, therefore it does not execute PEVerify. But .... Assembly.LoadFrom () will still load it, and GetTypes () will throw a ReflectionTypeLoadException exception, the .LoaderExceptions array shows me which link cannot be found. At the moment I am blocked.

However, the large Reflector Tool can go further and actually display the contained types and correctly handle the missing help problem by providing me with a pop-up dialog to view it. My question is: how after GetTypes () fails, will the reflector be able to get the types anyway?

+3
source share
3 answers

The reflector does not use System.Reflection to analyze the assembly.

I don't know which library Reflector uses, but you might want to take a look at Cecil .

+5
source

Module.GetTypes()will throw the same exception. If you catch ReflectionTypeLoadExceptionfrom a call Assembly.GetTypes(), this exception will have the β€œTypes” property on it of all types that it could load. Those that he could not be described in detail in the list / array property called LoaderExceptions.

+4
source

, , , , , .

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();

}

, , .

0

Source: https://habr.com/ru/post/1722744/


All Articles