Search code examples
c#assembly-resolution

Get assembly's requireed assemblies?


I am loading an assembly X.dll in my program, where X.dll can be anything, and I create an instance of the class X.A_Class. But what if the assembly X requires assemblies A, B, C and D?
How do I detect this?
How do I load them without holding them in a variable?


Solution

  • You can use Assembly.GetReferencedAssemblies as @alexn mentioned, and then use Assembly.Load to load them. Alternatively, you can hook AppDomain.CurrentDomain.AssemblyResolve and load them on demand.

    If you do need to iterate them, make sure you do it recursively to get transitive dependencies.