I am trying to determine every single reference inside a dll with System.Reflection. However, GetReferencedAssemblies only lists the ones in the “References” (visible in solution explorer).
I would like to determine references from within the code itself, such as an imports statement. Even things like if/then statements, try/catch, absolutely everything.
Is this possible to do using System.Reflection? If so, how?
I would definitely prefer to do this without p/invoke.
Thanks for the help!
This is in vb.net.
EDIT
As described by your later comment, you only want the assemblies that your code uses directly.
GetReferencedAssemblieswill do that.As described by your comments, you’re trying to solve the halting problem.You cannot reliably do this without actually executing the original assembly (and using the profiling API to see what type it uses).
You could recursively call
GetReferencedAssemblieson each reference and get the entire tree of indirect dependencies.EDIT:
For example:
However, you can get false positives if one of the references uses an assembly in a code path that isn’t reachable by the original assembly. Due to interfaces and polymorphism, it can be very difficult to weed out such false positives. If any of code in any reachable code path uses reflection, it is impossible by definition.