Reputation: 366
I would like to get a list of all the dlls loaded for a given Process. I am currently using .NET Framework 4.0. I am aware that there is a bug when trying to access all managed dlls through the Process.Modules property. (Only lists the unmanaged dlls). I need a way to programmatically retrieve all of these dlls.
Process[] myProcess = Process.GetProcessesByName("MyProcess");
if(myProcess.Count() > 0)
{
foreach (ProcessModule processModule in myProcess[0].Modules)
//get information
}
EDIT: The process I am interested in is not in the current AppDomain.
Upvotes: 6
Views: 5466
Reputation: 942207
I am aware that there is a bug
No, that's not a bug. It was an intentional design change in CLR v4, Microsoft did not keep that a secret. Previous versions of the CLR made an effort to emulate loaded assemblies as though they were unmanaged DLLs. But that just stopped making sense when they implemented the side-by-side in-process CLR versioning feature. It's gone and won't come back.
This isn't exactly a major problem, getting the list of loaded assemblies in another process is well supported by the debugging interface. ICorDebugAppDomain::EnumerateAssemblies() is the ticket. Well, not exactly as easy to use as Process.Modules. Use the MDbg sample to find out how to use it.
Upvotes: 6