views:

212

answers:

3

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.

+3  A: 

Sounds like you need NDepend.

(If you are writing a tool to analyze an app that's a big task)

Paul Kohler
Any free products like that?
Cyclone
there is a reason int's not free! I am not aware of any...
Paul Kohler
+2  A: 
SLaks
Sounds like a hassle. You would think they would have included something like a `GetAllAssemblies` method or something. With your recursion idea, the problem is that this would ONLY get the references for the referenced assemblies. I only want to deal with assemblies referenced directly within the dll itself, if that makes sense. This whole concept is rather confusing certainly...
Cyclone
What do you mean?
SLaks
I mean, I do not care about assemblies which are referenced within referenced assemblies. I only wish to derive assemblies from the dll itself.
Cyclone
Then `GetReferencedAssemblies` **will** do what you're looking for.
SLaks
+1  A: 

You are confusing namespace names with assembly names. System.IO is a namespace. It actually appears in more than one assembly. The System.IO.File class lives in mscorlib.dll, System.IO.FileSystemWatcher in system.dll, System.IO.Pipes.PipeStream in system.core.dll

GetReferencedAssemblies is accurate.

Play around with Red Gate's Reflector before writing this code.

Hans Passant
+1 for figuring out what he's talking about.
SLaks