C# 如何列出所有已加载的程序集?
在.Net中,我想枚举所有AppDomain上所有加载的程序集。为我的程序的AppDomain执行此操作非常简单C# 如何列出所有已加载的程序集?,c#,.net,assemblies,C#,.net,Assemblies,在.Net中,我想枚举所有AppDomain上所有加载的程序集。为我的程序的AppDomain执行此操作非常简单AppDomain.CurrentDomain.GetAssemblys()。我是否需要以某种方式访问每个AppDomain?或者已经有这样的工具了吗?使用Visual Studio 将调试器附加到进程(例如,从调试开始或调试>附加到进程) 调试时,显示模块窗口(调试>窗口>模块) 这提供了每个程序集、应用程序域的详细信息,并提供了一些加载符号的选项(即包含调试信息的pdb文件) 使
AppDomain.CurrentDomain.GetAssemblys()
。我是否需要以某种方式访问每个AppDomain?或者已经有这样的工具了吗?使用Visual Studio
勾选解释如何做的问题。以下是我的结论。这是所有属性和方法的列表,我列出了每个方法的所有参数。我没有成功地获得所有的价值观
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>");
}
}
}
}
foreach(System.Reflection.Assembly.getExecutionGassembly().getReferenceAssemblys()中的System.Reflection.AssemblyName){
System.Reflection.Assembly asm=System.Reflection.Assembly.Load(an.ToString());
foreach(asm.GetTypes()中的类型){
//性质
foreach(type.GetProperties()中的System.Reflection.PropertyInfo属性){
if(property.CanRead){
Response.Write(“
”+an.ToString()+”+type.ToString()+”+property.Name);
}
}
//方法
var methods=type.GetMethods();
foreach(方法中的System.Reflection.MethodInfo方法){
Response.Write(“
”+an.ToString()+”+type.ToString()+“+method.Name+”);
foreach(方法.GetParameters()中的System.Reflection.ParameterInfo参数)
{
Response.Write(“
Param=“+Param.Name.ToString());
Response.Write(“
Type=“+param.ParameterType.ToString());
Response.Write(“
Position=“+param.Position.ToString());
Response.Write(“
可选=“+param.IsOptional.ToString()+”);
}
}
}
}
btw。。。我从最初的帖子中排除了它,但我过滤了一些响应,比如soforeach(在asm.GetTypes()中键入Type){if((Type.ToString().IndexOf(“aclassmlooking”)>=0)|;(Type.ToString().IndexOf(“bclassimlooking”)>=0)){…
这根本没有回答问题。而不是使用getExecutiveGassembly(),我使用GetEntryAssembly()确保获得程序使用的程序集的更好列表。如果ExecutionGassembly恰好是一个DLL,我将错过其中一些。请尝试使用:Assembly[]Assembly=AppDomain.CurrentDomain.GetAssembly();它甚至比这里解释的更好,因为在流程的属性页中,process Explorer会精确显示加载到哪个AppDomain(包括“共享域”)程序集。因此,它显示的不仅仅是加载到流程中的.dll。如果知道它们使用什么API来显示这一点,那将非常好(关于的“编程”链接将只提供CurrentDomain中的程序集)。请注意,GetAssemblys()
不起作用,因为它不是递归的,并且会丢失任何嵌套的程序集引用。我已在@Contango:AppDomain.CurrentDomain.GetAssemblys()处添加了一个递归版本的GetAssemblys()
。@Contango:AppDomain.CurrentDomain.GetAssemblys()
非常好。它不需要递归遍历引用,因为它首先不枚举引用。这是否回答了您的问题?