How do I list all loaded assemblies?

C#.NetAssemblies

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbtin ForouzandehView Question on Stackoverflow
Solution 1 - C#Bogdan Gavril MSFTView Answer on Stackoverflow
Solution 2 - C#s15199dView Answer on Stackoverflow