How do I list all loaded assemblies?

后端 未结 2 1562
鱼传尺愫
鱼传尺愫 2020-11-27 15:09

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

相关标签:
2条回答
  • 2020-11-27 15:39

    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>");
                        }
                    }
                }
            }
    
    0 讨论(0)
  • 2020-11-27 15:46

    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).

    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.

    0 讨论(0)
提交回复
热议问题