Ongoing

Kozen's Blog

导航

Assembly的LoadFile()和LoadFrom()的区别

Posted on 2005-10-26 14:24  Kozen  阅读(1950)  评论(1编辑  收藏  举报

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. Do not use LoadFile to load assemblies that you want to execute.
LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.


即不同物理位置的相同程序集通过LoadFile加载后,实例化其中的对象后不能进行类型比较,因为没有相同的环境。所以在类似插件系统的程序集动态加载的实现中应该使用LoadFrom方法(btw:调用后不会自动加载依赖的程序集)。