Closed
Description
There is a DLL written in native C++ using CLR Profiling API.
I need to build a dependency tree of all managed assemblies/modules of the process, starting from its main module, using the same native C++, possibly using the same CLR Profiling API or other arsenal of the CLR.
For each assembly/module, I need to know the full path to it.
Something like this approach in C#, but in unmanaged C++.
Dictionary<string, List<string>> GetDependencies(string assemblyPath)
{
var dependencies = new Dictionary<string, List<string>>();
var assembly = Assembly.LoadFrom(assemblyPath);
var referencedAssemblies = assembly.GetReferencedAssemblies();
dependencies[assembly.FullName] = new List<string> { assembly.Location };
foreach (var referencedAssembly in referencedAssemblies)
{
string referencedAssemblyPath = Path.Combine(Path.GetDirectoryName(assemblyPath), referencedAssembly.Name + ".dll");
dependencies[assembly.FullName].Add(referencedAssemblyPath);
var subDependencies = GetDependencies(referencedAssemblyPath);
foreach (var subDependency in subDependencies)
{
if (!dependencies.ContainsKey(subDependency.Key))
{
dependencies[subDependency.Key] = subDependency.Value;
}
}
}
return dependencies;
}
How can this be implemented? Please give me some hints.
Ideally, I need a solution that would work for all versions of .NET/Core/Framework.
For some reason, the profiler callbacks AssemblyLoadStarted
/ AssemblyLoadFinished
are not called for me (given the correct event mask). Therefore, solutions with these methods are unlikely to help.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status