none
Process.Modules does not give correct result RRS feed

  • Question

  • I'm using the Process.Modules property to get a list of loaded modules in my appliaction. This used to work well, but now it doesn't anymore. Not sure if it's VS2010, .NET 4.0 or anything else, but this property does not list all the modules that are loaded in my process.

    For instance, it only returns 120 modules, but if I look in Process Explorer, it is 244 loaded modules in the process.

    Problem is that EnumProcessModules gives the same invalid result.

    Does anyone have any information on this, and how to fix it?

    regards,
    Staffan

    Wednesday, August 10, 2011 1:37 PM

All replies

  • This is a bug in .Net 4.0. Process.Modules in .Net 4.0 just lists the unmanaged dll's. Check this link post which gives more details http://social.msdn.microsoft.com/Forums/nl-BE/netfxappcompatprerelease/thread/5bc8a424-8770-4a34-80e4-6108ea95c28d
    Thursday, August 11, 2011 11:27 AM
  • Thanks for the reply. However, I'm not very happy with the information in that thread. Karel Zikmund states that "CLR team is making sure that it is properly documented and hopefully there should be a workaround code-snippet available soon". Yes, it is documented in the .NET 4 Migration topic, but I think that it should be documented in the online help at the http://msdn.microsoft.com/en-us/library/system.diagnostics.process.modules.aspx page, as well as a workaround.

    /Staffan


    Thursday, August 11, 2011 1:07 PM
  • Actually, you may add your suggestion at the Community Content section of the document page.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 12, 2011 3:18 AM
  • Done!

    However, the "how to fix it?" question is not answered.

    /Staffan

    Friday, August 12, 2011 6:24 AM
  • Done!

    However, the "how to fix it?" question is not answered.

    /Staffan


    I doubt that it will be "fixed".  If you want managed and unmanaged modules, reference a class library that uses the .NET 3.5 Process class.
    Friday, August 12, 2011 6:28 AM
  • With "fixed" I meant a workaround, for instance with VirtualQuery/GetMappedFileName.
    Friday, August 12, 2011 6:34 AM
  • Done!

    However, the "how to fix it?" question is not answered.

    /Staffan


    I doubt that it will be "fixed".  If you want managed and unmanaged modules, reference a class library that uses the .NET 3.5 Process class.

    Btw, referencing a 3.5 (or 2.0) class library won't do, because the "Process" returned in Process.GetCurrentProcess() is still .NET 4.0, so the .NET 3.5 library will still not return the complete list.
    Friday, August 12, 2011 11:02 AM
  • Btw, referencing a 3.5 (or 2.0) class library won't do, because the "Process" returned in Process.GetCurrentProcess() is still .NET 4.0, so the .NET 3.5 library will still not return the complete list.

    Yeh!  A dll runs in the 4.0 process.  A redirected console app works.
    Friday, August 12, 2011 3:24 PM