Get the paths of all referenced assemblies

后端 未结 4 1545
感情败类
感情败类 2021-01-11 13:48

How do I get the paths of all the assemblies referenced by the currently executing assembly? GetReferencedAssmblies() gives me the AssemblyName[]s.

4条回答
  •  囚心锁ツ
    2021-01-11 14:23

    You cannot know until the assembly is loaded. The assembly resolution algorithm is complicated and you can't reliably guess up front what it will do. Calling the Assembly.Load(AssemblyName) override will get you a reference to the assembly, and its Location property tells you what you need.

    However, you really don't want to load assemblies up front, before the JIT compiler does it. It is inefficient and the likelihood of problems is not zero. You could for example fire an AppDomain.AssemblyResolve event before the program is ready to respond to it. Avoid asking this question.

提交回复
热议问题