从具体路径负载强名称程序集? [英] Load strongly-name assembly from specific path?
问题描述
我有一个强烈的命名程序集,安装到特定的文件夹(而不是GAC)
I have a strongly-named assembly, installed to a specific folder (and not the GAC).
在反射器中显示的名称是:
The name as shown in Reflector is:
"Foo.Bar.TreeFrog, Version=1.2.1.0, Culture=neutral, PublicKeyToken=ac88c4a8b22089b4"
和它的安装路径是
"c:\\QueueBall"
我可以使用大会。负载
或 Assembly.LoadFrom
加载它,如果又如何?
Can I use Assembly.Load
or Assembly.LoadFrom
to load it, and if so how?
灿我保证强命名是荣幸,即是我加载真的DLL是一个我期待并没有使用相同的名字冒名顶替?
Can I ensure that the strong naming is honored, i.e. that the DLL I'm loading really is the one I'm expecting and not an imposter with the same name?
推荐答案
您可以使用 LoadFrom :
var assembly = Assembly.LoadFrom(@"c:\QueueBall\Foo.Bar.TreeFrog.dll");
请注意,这也将引用的程序加载到运行该代码的应用程序域。如果你不希望这种行为,你可以使用的LoadFile 方法。
Note that this will also load referenced assemblies into the application domain running this code. If you don't want this behavior you could use the LoadFile method.
更新:
您可以加载它,以确保前检查程序集标识它没有被篡改:
You can check the assembly identity before loading it to make sure that it has not been tampered with:
AssemblyName an = AssemblyName.GetAssemblyName(@"c:\QueueBall\Foo.Bar.TreeFrog.dll");
byte[] key = an.GetPublicKey();
Version version = an.Version;
这篇关于从具体路径负载强名称程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!