我怎样才能从从另一个文件夹中加载的程序集的类型? [英] How can I get a type from an assembly that is loaded from within another folder?
问题描述
我用下面的code:
Assembly.LoadFile("the assembly in another folder");
var type = Type.GetType("the full name of the type");
尽管组装这一行的code之前已加载,它总是以返回null键入
。
PS:我也通过在装配合格的名称,包括命名空间,类型名称,程序集名称,版本和公共标记
PS: I did pass in the assembly qualified name, including namespace, type name, assembly name, version and public token.
推荐答案
Type.GetType
只搜索在mscorlib.dll在调用组件的种类和类型,除非你通过该类型的程序集限定名。 在这里看到。
Type.GetType
only searches the types in the calling assembly and the types in mscorlib.dll unless you pass the assembly qualified name of the type. See here.
修改
看来, Type.GetType
仅能够从加载上下文组件检索键入
实例。大会通过加载的LoadFile
是的没有上下文以及那些使用负载 LoadFrom
是在负荷范围内;没有这些情况下都允许您使用 Type.GetType
所以分辨率将失败。 本文说明键入
信息能够为组装
时,该目录是在被添加为一个探测privatePath,因为它会结束了在负载范围内,但会在其他方面失败。
It appears that Type.GetType
is only able to retrieve Type
instances from assemblies in the Load context. Assemblies loaded using LoadFile
are in no context and those loaded using LoadFrom
are in the Load From context; neither of these contexts allow you to use Type.GetType
so the resolution will fail. This article shows that Type
information can be retrieved for an Assembly
when the directory it is in is added as a probing privatePath since it will then end up in the Load context but will fail in other contexts.
这篇关于我怎样才能从从另一个文件夹中加载的程序集的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!