0

Is there a simple way to see for a running .Net application, all the classes that have been loaded so far? This would be helpful in removing classes that are no longer being used in a large project.

I know I could put static initializers in every class and have them do some sort of registration, but this is tedious and error-prone. It would be great if there was a cleaner way to do it through the AppDomain or Assembly class or something. Thanks!

nganju
  • 720
  • 6
  • 16

2 Answers2

0

you can find which Assemblies are loaded in the current app domain really easily - AppDomain.CurrentDomain.GetAssemblies(). Of course, it'll just give you the information about assemblies loaded in the specific time when you execute this. There are much better ways to find and clean redundant code in the solution. Personally, i like ReSharper. it has great feature called "Find code issues" (can be used for the entire solution) which will give you a list of unused symbols, which is exactly what you're looking for.

Shahar Gvirtz
  • 2,418
  • 1
  • 14
  • 17
  • ReSharper falls short because there might be an endpoint (for example, web page or RESTful API call) which references a class, but the endpoint is never used anymore. So the class is referenced at compile time but never used in practice. – nganju Sep 22 '12 at 19:03
0

You could use an aspect library like PostSharp, Spring.Aop to intercept all calls to methods, properties etc. and add the type name to a set. Another way would be to use a profiler. Both approaches, unfortunately need you to keep using the application (hopefully it's a desktop application with a UI).

By the way have you tried to enable CodeAnalysis and look for Performance warnings? You will receive warnings for all methods, properties, fields that are never called.

Panos Rontogiannis
  • 4,154
  • 1
  • 24
  • 29