dynamically analyzing dlls for code resuse

A

Adman

Hi all...

At my work, we have a large number of dlls. Each dll is typically a
single class, and each class has any number of methods in it. We have
"core" objects that generally contain reuseable code, as well as
application-specific objects which usually make use of our core
objects.

What I'd like to do is get some sort of count to see how often our core
objects are used by our applications.

For example, say we have the following objects making calls:

"-->" means "calls a method in"

App1 --> Core1 --> Core2
App1 --> Core1 --> Core3
App2 --> Core1
App3 --> Core2

If I use Reflection, I can easily load up App1, and see that it depends
on Core1. I can then load up Core1 and see that it depends on Core2
and Core3 (and perhaps others)

However, I'd also like to know that App1 depends indirectly on Core2
and Core3.

Conversely, when I load up App2, I'd like to see that it's dependant on
(or, at least, calls a method in) Core1, but does NOT actually
need/use/touch Core2 or Core3.

Does that make sense?

I somehow need to trace actual method calls and keep a running count of
what objects are touched. Just finding out dependancies isn't good
enough (it either includes too much or not enough information).

Any ideas?

I think reflection isn't useful here. One thought is to use ILDASM to
disassemble every dll, and then parse the output. Possible, but it
seems like a mess.

What I'd really like some sort of diassembler that I access
programatically... so that I could load up a type, load up a method,
see who it calls, and then load up the target assembly/method, and
trace through it that way (a depth first search, basically).

Thanks for any help/advice you might have!

Adam
 
A

Adman

Thanks... that definitely looks like it's on the right track. I have
Reflector, and was pleasantly surprised to hear there was an API for
it.

However, the sample code in the MSDN article doesn't compile for me...

IServiceProvider serviceProvider = new Application(null);
IAssemblyLoader assemblyLoader = (IAssemblyLoader)
serviceProvider.GetService(typeof(IAssemblyLoader));
IAssembly rAssembly =
assemblyLoader.LoadFile("..\\..\\..\\CombinationsLib.dll");


The compiler doesn't know what "Application" is, as well as
IAssemblyLoader.

I'll keep poking around and see what I can do. Thanks for the lead,
and if anyone has any further thoughts, I appreciate it!

Adam
 
A

Adman

PS: Could IAssemblyLoader have been replaced with IAssemblyManager?
IAssemblyLoader doesn't seem to exist in the Reflector API (I believe I
have the latest version (4.2.42)), and IAssemblyManager has a LoadFile
method...

This is still giving me trouble, though... I've never used
IServiceProvider...

IServiceProvider serviceProvider = new Application(null);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top