C# Reflection: Get *all* active assemblies in a solution?
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
This will get all of the loaded assemblies in the current AppDomain.
As noted in the comments, it's possible to spawn multiple AppDomains, in which case each can have its own assemblies. The immediate advantage to doing so is that you can unload Assemblies by unloading the containing AppDomain.
This is a really old question, but for future reference here's a complete implementation:
public static IEnumerable<Assembly> GetAssemblies()
{
var list = new List<string>();
var stack = new Stack<Assembly>();
stack.Push(Assembly.GetEntryAssembly());
do
{
var asm = stack.Pop();
yield return asm;
foreach (var reference in asm.GetReferencedAssemblies())
if (!list.Contains(reference.FullName))
{
stack.Push(Assembly.Load(reference));
list.Add(reference.FullName);
}
}
while (stack.Count > 0);
}
Also: Some assemblies are not loaded straight away, so you should also put an Event Handler on the AppDomain's assembly load event.
AppDomain.CurrentDomain.AssemblyLoad += ....