By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,780 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,780 IT Pros & Developers. It's quick & easy.

dynamically analyzing dlls for code resuse

P: n/a
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

May 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Check out http://msdn.microsoft.com/msdnmag/issues/06/03/TestRun/ and
see if it is of any help

May 17 '06 #2

P: n/a
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("..\\..\\..\\CombinationsL ib.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

May 17 '06 #3

P: n/a
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);

May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.