How to List All Loaded Assemblies

How do I list all loaded assemblies?

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

Sample Image

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.

How do I get a list of all currently loaded assemblies?

Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();

Get list of loaded Assemblies on UAP10 platform

One way to kinda do what you want is to get the DLLs/assemblies which is located in the folder in which your app is installed (which one can assume in some cases is being used/loaded in your app).

    public static async Task<List<Assembly>> GetAssemblyList()
{
List<Assembly> assemblies = new List<Assembly>();

var files = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFilesAsync();
if (files == null)
return assemblies;

foreach (var file in files.Where(file => file.FileType == ".dll" || file.FileType == ".exe"))
{
try
{
assemblies.Add(Assembly.Load(new AssemblyName(file.DisplayName)));
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

}

return assemblies;
}

Then to loop through them you could do:

foreach (var assembly in GetAssemblyList().Result)
{
//Do something with it
}

Credits to this reddit thread/user.

How do I get a list of all loaded Types in C#?

List<Type> list = new List<Type>();
foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type t in ass.GetExportedTypes())
{
if (t.IsEnum)
{
list.Add(t);
}
}
}

That should do, for all assemblies loaded by the current Appdomain, to get just from defined assemblies, just adjust ;-)

How to get a programmatic list of all loaded assemblies (referenced) in the .NET Compact Framework

Based on this it would appear that managed dll's are not truly 'loaded' in the sense that they are in the conventional framework. Instead the IL is memory mapped and the JIT just grabs what it needs as it goes along (saving having to maintain a load of memory for code that has executed but is no longer used)

This would explain why the CF provides no way to iterate over the loaded dll's. As to why it doesn't allow iterating over the referenced dlls which are an entirely complie time construct...

As a possible work around:

Use GetExecutingAssembly to get the active code. Ensure that this happens in your executable so it gets the root assembly.

Write some code capable of parsing the dll for the manifest indicating which assemblies are referenced (this need not be managed code - the unmanaged introspection API microsoft provides may even do this for you and the dll format specification is both public and unlikely to radically change in the near future). I suggest black listing dll's loaded from the GAC (though this may be unnecessary).

How can I get a list of all assemblies that have been called by the current program?

I called:

AppDomain.CurrentDomain.GetAssemblies()

then I looped through them.



Related Topics



Leave a reply



Submit