如何列出所有已加载的程序集?

进去。Net,我想枚举所有应用程序域上的所有已加载程序集。在我的程序的 AppDomain 中这样做非常容易。我需要以某种方式访问每个应用程序域吗?还是已经有这样的工具了?

114164 次浏览

Using Visual Studio

  1. Attach a debugger to the process (e.g. start with debugging or Debug > Attach to process)
  2. 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).

enter image description here

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.

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>");
}
}
}
}