我有 System.Reflection 的问题,当我调用 MethodInfo.Invoke 方法时,它给了我 TargetException 异常,上面写着:对象与目标不匹配,这里的代码:
object[] parms = new object[] { path };
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type gameType = null;
foreach (Assembly asm in assemblies)
{
string asmName = asm.GetName().Name;
if (asmName == "Tester")
{
gameType = asm.GetType("Tester.Main");
break;
}
}
var game = Convert.ChangeType(GameInstance, gameType);
Type delegateType = game.GetType().GetEvent("gameVideoLoader").EventHandlerType;
MethodInfo method = delegateType.GetMethod("Invoke");
method.Invoke(game, parms); // Here the exception
任何想法?PS:游戏对象已正确分配,因此它不为空