演示: 我的项目中有两个类库。 1)行动2)过程。
我的操作库包含接口IProcessor ,其中包含方法流程。
在我的Process Library中我有3个班级
A)ClassA:IProcessor
B)ClassB:IProcessor
C)ClassC:IProcessor
实现IProcessor接口。
当我尝试阅读Process Library的程序集时,我没有使用任何类型的ClassA,ClassB和ClassC
我用过
Assembly processorAssembly = Assembly.LoadFile(process.dll);
Type submitOfferType = processorAssembly.GetType("Namespace.ClassA");
从汇编中读取类型。
如何从dll获取派生类型?
答案 0 :(得分:2)
将其更改为:
Type submitOfferType =
processorAssembly.GetType("NamespaceOfProcessLibrary.ClassA");
Assembly.GetType需要该类的全名。
答案 1 :(得分:1)
您应该使用Assembly.Load
或Assembly.LoadFrom
代替Assembly.LoadFile
。试试这个:
Assembly processorAssembly = Assembly.Load(AssemblyName.GetAssemblyName("[...]process.dll"));
Type submitOfferType = processorAssembly.GetType("Namespace.ClassA");
Assembly.LoadFile
不会尝试解析相对于您使用LoadFile
加载的文件的相关性,因此它甚至不会尝试解析您的操作库。显然它会解决它无法通过简单地忽略它们来加载依赖类型的问题。
答案 2 :(得分:0)
Assembly.GetType
期望该类型的全名。这意味着您必须包含命名空间。
答案 3 :(得分:0)
尝试找到“ClassA”的确切全名:
Assembly processorAssembly = Assembly.LoadFile(process.dll);
var types= processorAssembly.GetTypes();
检查调试器中“类型”的名称以获取真实姓名。