In .Net, I would like to enumerate all loaded assemblies over all AppDomains. Doing it for my program's AppDomain is easy enough AppDomain.CurrentDomain.GetAssemblies()
. Do I need to somehow access every AppDomain? Or is there already a tool that does this?
107
votes
2 Answers
104
votes
Using Visual Studio
- Attach a debugger to the process (e.g. start with debugging or Debug > Attach to process)
- While debugging, show the Modules window (Debug > Windows > Modules)
This gives details about each assembly, app domain and has a few options to load symbols (i.e. pdb files that contain debug information).
Using Process Explorer
If you want an external tool you can use the Process Explorer (freeware, published by Microsoft)
Click on a process and it will show a list with all the assemblies used. The tool is pretty good as it shows other information such as file handles etc.
Programmatically
Check this SO question that explains how to do it.
23
votes
Here's what I ended up with. It's a listing of all properties and methods, and I listed all parameters for each method. I didn't succeed on getting all of the values.
foreach(System.Reflection.AssemblyName an in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies()){
System.Reflection.Assembly asm = System.Reflection.Assembly.Load(an.ToString());
foreach(Type type in asm.GetTypes()){
//PROPERTIES
foreach (System.Reflection.PropertyInfo property in type.GetProperties()){
if (property.CanRead){
Response.Write("<br>" + an.ToString() + "." + type.ToString() + "." + property.Name);
}
}
//METHODS
var methods = type.GetMethods();
foreach (System.Reflection.MethodInfo method in methods){
Response.Write("<br><b>" + an.ToString() + "." + type.ToString() + "." + method.Name + "</b>");
foreach (System.Reflection.ParameterInfo param in method.GetParameters())
{
Response.Write("<br><i>Param=" + param.Name.ToString());
Response.Write("<br> Type=" + param.ParameterType.ToString());
Response.Write("<br> Position=" + param.Position.ToString());
Response.Write("<br> Optional=" + param.IsOptional.ToString() + "</i>");
}
}
}
}
GetAssemblies()
won't work, as it is not recursive and it will miss out any nested assembly references. I've added a recursive version ofGetAssemblies()
at stackoverflow.com/questions/383686/…. – ContangoAppDomain.CurrentDomain.GetAssemblies()
is perfectly fine. It doesn't need to walk references recursively, because it isn't enumerating references in the first place. – Ben Voigt