Get Location of loaded assembly using .Net Profiling API RRS feed

  • Question

  • I am writing a profiler that uses the .NET Profiling API.I want to do some analysis on all the assemblies that are loaded by the profiled application.

    I can get the AssemblyID by using the AssemblyLoadStarted method of ICorProfilerCallback interface, using this assembly id i want to get

    1. Assembly name
    2. Full path of the file location where the assembly is stored

    Is it possible to get both using Profiling API?

    Wednesday, August 5, 2015 2:47 PM


  • Both of these come from the manifested module.

    To get the assembly name, use ICorProfilerInfo::GetModuleMetaData to get a IMetaDataAssemblyImport and then GetAssemblyFromScope and GetAssemblyProps to get the assembly name (GetAssemblyFromScope will fail if the module is not manifested, only one module per assembly will be manifested).

    The common interpretation of "full path to the assembly" is actually the full path to manifest module of the assembly, you use GetModuleInfo2 to get the 'name' which, IIRC, is actually the path to the module (if the module was loaded from disk, it could be empty or some other text if the assembly was dynamic - check the pdwModuleFlags returned by GetModuleInfo2).

    In most cases you will start from the module, but if you really do need to start from the AssemblyID, then you can use ICorProfilerInfo::GetAssemblyInfo to get the manifest ModuleID (looks like it might also be able to provide you with the assembly name).

    Wednesday, August 5, 2015 10:13 PM