使用反射创建装配对象 [英] Create assembly object using reflection
本文介绍了使用反射创建装配对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想创建MyClass
的对象,该对象位于commr.dll中的Commr.MyClass
命名空间内. MyClass实现ICommr
接口.以下是代码...
Hello Everyone,
I want to create an object of MyClass
which is inside Commr.MyClass
namespace in commr.dll. MyClass implement the ICommr
Interface. Following is the code...
Assembly myDllAssembly = Assembly.LoadFile(@"D:\commr.dll");
ICommr valCommr =(ICommr)myDllAssembly.CreateInstance("Commr.MyClass");
string str = valCommr.GetSetting();
但这给了我一个错误:Unable to cast object of type Commr.MyClass'' to type ''LoadAssembly.ICommr''
.
您能帮我解决这个问题吗?
谢谢.
But it gives me a error : Unable to cast object of type Commr.MyClass'' to type ''LoadAssembly.ICommr''
.
Can you please help me to slove this issue ?
Thanks.
推荐答案
您需要确保Commr.MyClass实现ICommr接口.
You need to ensure that Commr.MyClass implements ICommr interface.
这篇关于使用反射创建装配对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文