如何从GAC加载程序集? [英] How would I load an assembly from the GAC?
问题描述
我正在尝试使用Assembly.Load()加载GAC中的程序集。例如,说我想列出 PresentationCore.dll 中存在的所有类型,我该如何加载 PresentationCore.dll ?
当我尝试以下操作时:
Assembly a = Assembly.Load( PresentationCore.dll );
我收到 FileNotFoundException 。
I'm trying to use Assembly.Load() to load an assembly that is in the GAC. For example, say I want to list out all of the types that exist in PresentationCore.dll, how would I go about loading PresentationCore.dll?
When I try this:
Assembly a = Assembly.Load("PresentationCore.dll");
I get a FileNotFoundException. Another answer on SO suggested I used Assembly.LoadFrom() to accomplish this - I'm hesitant to do that because Assembly.LoadFrom() is deprecated, according to Visual Studio 2008 - plus, it doesn't seem to actually work.
Any ideas?
If the assembly is in the GAC you must load it via its fully qualified name.
For example, if I wanted to load mscorlib.dll
I would do something like this:
Assembly a = Assembly.Load
("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
The easiest way to determine an assembly's fully qualified name is to load the assembly in Reflector and use the Name field from the lower display pane like this:
这篇关于如何从GAC加载程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!