1

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?

1
  • 3
    Assembly.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. Commented Aug 6, 2014 at 11:47

1 Answer 1

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]

Sign up to request clarification or add additional context in comments.

2 Comments

Also can we load simply gac dll without providing the version?
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: stackoverflow.com/questions/1599575/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.