开发者

Get assembly's requireed assemblies?

开发者 https://www.devze.com 2023-02-08 09:02 出处:网络
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

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?


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.


You can get the referenced assemblies for an assembly with the Assembly.GetReferencedAssemblies method.


Refferenced assemblies normally will be loaded automatically (see related messages like How is an assembly resolved in .NET? for starting links).

If you are loading assemblies not from standard locations (like GAC and application's root folder) you may need either setup path to load referenced assemblies from (search for "assembly default load path" - i.e. app config file - http://msdn.microsoft.com/en-us/library/823z9h8w.aspx) or load them yourself from AssemblyReslove event as mentioned in other answers.

The best way to start debugging the issues with loading assemblies is read blogs at: http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx (and related posts http://blogs.msdn.com/b/suzcook/archive/tags/loader+debugging+advice/ )

EDIT: folder -> "root folder" + link to config file topic for probing paths.

0

精彩评论

暂无评论...
验证码 换一张
取 消