How to determine what other dll/exe is being used by a particular .net dll/exe? In simple words i want to find out the dependencies of a particular .net dll/exe which is in Global Assembly Cache. How can it be read via system.reflection?
Asked
Active
Viewed 308 times
1
-
3Assembly.GetReferencedAssemblies(). These are *known* dependencies, reflection code in the assembly can add unknown ones. You'd have to dig though embedded resources as well. COM interop and pinvoke adds more yet. – Hans Passant Aug 06 '14 at 11:47
1 Answers
1
As @Hans Passant pointed out in his comment, you can use the GetReferencedAssemblies
method to retrieve the referenced assemblies of a dll (i.e. the "known" dependencies):
var assembly = Assembly.Load("Microsoft.ActiveDirectory.Management, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
var referencedAssemblies = assembly.GetReferencedAssemblies();
foreach (var referencedAssembly in referencedAssemblies)
{
Console.WriteLine(referencedAssembly.FullName);
}
The Assembly.Load()
method will load an Assembly from the GAC if you fully qualify it with the Version
, Culture
, and PublicKeyToken
. [reference]
-
-
No, you have to supply the version of the assembly. Otherwise you will receive a `FileNotFoundException`. You may be able to discover those additional details, however, by attempting to browse through the GAC's contents (such as in this answer: http://stackoverflow.com/questions/1599575/enumerating-assemblies-in-gac) – skeryl Aug 06 '14 at 13:38