Hi all,

I am trying to get the all the process modules from the Current process using "ProcessModuleCollection" Class. Please see the code i have used to do the above job. Before that I added a .net 2.0 my own dll to the project as reference. I am able to see that dll in process modules list from the below Code.

So the problem is, when i added a .net 4.0 dll to the project of of same 4.0 version with the same code, i am not able to see the 4.0 dll in the Modules list...I used the same code as below, only project and the dll versions used are 4.0.

I dont know, why it is not working. Please help me to resolve this issue. Thanks in Advance..

Process currentProcess = Process.GetCurrentProcess();

Process[] ObjModulesList = Process.GetProcessesByName(currentProcess.ProcessName);

// Populate the module collection.
ProcessModuleCollection ObjModules = ObjModulesList[0].Modules;

Sudheer Kokirala

I can think of two reasons that you get these results:
1) The module isn't being loaded in 4.0 as the compiler is 'smarter' and it doesn't need to load it.
2) The module hasn't been loaded *yet*. The system is still in the act of loading modules when you request this information.

You can ensure that it is loaded by using something from the DLL before you get the module list, since it will have to have loaded it to use it. Have you tried this?

Thanks for the reply Momerath...

I tried what you said, still the 4.0 dll is not loading into the modules collection list.

Try just using the Modules property of the process:

Process currentProcess = Process.GetCurrentProcess();

// Populate the module collection.
ProcessModuleCollection ObjModules = currentProcess.Modules;
This article has been dead for over six months. Start a new discussion instead.