调用时出现 TargetException
TargetException on Invoke
我的 Invoke()
抛出 TargetException 有问题。
public Controller(SystemUI ui, System system)
{
UI = ui;
System = system;
UI.CommandEntered += ParseCommand;
Commands = new Dictionary<string, Delegate>();
Commands.Add(":q", new Action(UI.Close));
}
然后我调用 Commands[input[0]].Method.Invoke(this, input.ToArray<object>());
,但它抛出 TargetException 消息
Object does not match target type.
我需要演员表吗?
我很迷茫,如果有任何帮助,我将不胜感激!
根据上面的评论,您正在尝试调用一个操作 (UI.Close),但您正在将一个对象数组作为参数传递给此操作,该操作没有参数,因此会引发此异常。
改变...
input.toArray<object>()
到...
new object[0], or new object[] {} // or perhaps even just null may do the trick.
我的 Invoke()
抛出 TargetException 有问题。
public Controller(SystemUI ui, System system)
{
UI = ui;
System = system;
UI.CommandEntered += ParseCommand;
Commands = new Dictionary<string, Delegate>();
Commands.Add(":q", new Action(UI.Close));
}
然后我调用 Commands[input[0]].Method.Invoke(this, input.ToArray<object>());
,但它抛出 TargetException 消息
Object does not match target type.
我需要演员表吗? 我很迷茫,如果有任何帮助,我将不胜感激!
根据上面的评论,您正在尝试调用一个操作 (UI.Close),但您正在将一个对象数组作为参数传递给此操作,该操作没有参数,因此会引发此异常。
改变...
input.toArray<object>()
到...
new object[0], or new object[] {} // or perhaps even just null may do the trick.