I am trying to call a routine defined in the main class when a treeview item is selected.
I have stored the routine name under the treenode tag element and I am excuting the following code when it is selected.
private
void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e){
if (e.Node.Tag == null){
} else{
Type theFunctionType = Type.GetType("XMLTree1.Form1");
Type[] paramTypes =
new Type[0];MethodInfo funcInfo = theFunctionType.GetMethod( e.Node.Tag.ToString(),paramTypes);
Object[] parameters =
new Object[0]; object result = funcInfo.Invoke(theFunctionType,parameters);}
}
The problem is when the funcinfo.Invoke is executed I get the following exception...
"An unhandled exception of type 'System.Reflection.TargetException' occurred in mscorlib.dll
Additional information: Object does not match target type."
Can someone help please I am stuck to why this occurs..
Thanks
Replies
Know the answer? Post it — somebody with the same question will find it here.