C# 如何列出所有加载的程序集?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/458362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I list all loaded assemblies?
提问by Abtin Forouzandeh
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?
在 .Net 中,我想枚举所有 AppDomains 上的所有加载的程序集。为我的程序的 AppDomain 做这件事很容易AppDomain.CurrentDomain.GetAssemblies()
。我是否需要以某种方式访问每个 AppDomain?或者已经有一个工具可以做到这一点?
采纳答案by Bogdan Gavril MSFT
Using Visual Studio
使用 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)
- 将调试器附加到进程(例如开始调试或调试 > 附加到进程)
- 调试时,显示模块窗口(调试 > Windows > 模块)
This gives details about each assembly, app domain and has a few options to load symbols (i.e. pdb files that contain debug information).
这提供了有关每个程序集、应用程序域的详细信息,并提供了一些加载符号的选项(即包含调试信息的 pdb 文件)。
Using Process Explorer
使用进程浏览器
If you want an external tool you can use the Process Explorer(freeware, published by Microsoft)
如果您需要外部工具,您可以使用Process Explorer(免费软件,由 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 SOquestion that explains how to do it.
检查这个 SO问题,它解释了如何做到这一点。
回答by s15199d
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>");
}
}
}
}