日期:2014-05-19  浏览次数:20896 次

反射出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);
}


改成这样试试.