February 24th, 2009
Show all assemblies loaded by your C# program - 3
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Sometimes it is handy to have a quick overview of all the assemblies that your C# program has loaded. Maybe because you are trying to debug a version conflict, or because you want to distribute your application and want to get an idea of its dependencies.
To find the loaded assemblies we first need to determine the current AppDomain (it is possible for your application to have more than one AppDomain, but in that case you have created the second one yourself). Each AppDomain keeps a list of Assemblies it is using and in the following example code we query it using the GetAssemblies() method.
By calling FullName we obtain the name, version, culture and public key ID for each assembly.
using System;
using System.Text;
using System.Reflection;
namespace AssemblyListing
{
class Program
{
static void Main(string[] args)
{
AppDomain MyDomain = AppDomain.CurrentDomain;
Assembly[] AssembliesLoaded = MyDomain.GetAssemblies();
foreach (Assembly MyAssembly in AssembliesLoaded)
{
Console.WriteLine("Loaded: {0}", MyAssembly.FullName);
}
}
}
}
Tags: c#, reflection









Except where otherwise noted, content on this site is
February 24th, 2009 at 7:56 pm
Yep, this is well useful for debugging version conficts, especially with apps that have a lot of assemblies.
Assuming you didn’t want to make further use of AppDomain and Assembly[], you could shorten this to:
foreach (Assembly MyAssembly in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(“Loaded: {0}”, MyAssembly.FullName);
}
Sometimes I’ve made use of this functionality in WinForms “About” boxes, by enabling a “Show Loaded Assemblies” button if the program is running in Debug mode.
February 24th, 2009 at 9:10 pm
Hi Gareth,
Thanks for the comment — I tried to keep things readable, but you are right of course.
Cheers,
Martijn
September 15th, 2009 at 8:22 pm
Excellent, this was very useful. I used it to know what classes are implementing an interface in a plugin based application when the plugins are loaded by another assembly.