首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

反射出TargetException 异常,请教何解?多谢!

2012-03-06 
反射出TargetException 错误,请问何解?急,在线等,谢谢!!调用端:stringfilepath@ E:\VS2005\DataCollecto

反射出TargetException 错误,请问何解?急,在线等,谢谢!!
调用端:
string   filepath   =   @ "E:\VS2005\DataCollector\DataCollector\Components\DataAnalyzer.dll ";
String   test   =   "分析中 ";
Assembly   myDllAssembly   =   Assembly.LoadFrom(filepath);
Type   dllType   =   myDllAssembly.GetType( "DataAnalyzer.Goodoon ");
if   (dllType!=null)
{
        MethodInfo   mi   =   dllType.GetMethod( "kkk ");
        String   nnn   =   (String)mi.Invoke(dllType,   null);     <----出错,TargetException  
        Console.WriteLine(nnn);
}


在DLL那边:
public   String   kkk()
{
        String   teststr   =   "abc ";
        return   teststr;
}


在出错行那里提示:对象与目标类型不匹配,TargetException  

请问何解?谢谢

[解决办法]
if (dllType!=null)
{
MethodInfo mi = dllType.GetMethod( "kkk ");
object o=Activator.CreateInstance(dllType);
String nnn = (String)mi.Invoke(o, null);
Console.WriteLine(nnn);
}


改成这样试试.

热点排行