InvokeMethod error with named parameters.

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Stevo (thestevebryant_at_hotmail.com)
Date: 04/02/04


Date: Fri, 2 Apr 2004 16:57:12 +1200

I have a strange error with the InvokeMethod. Parameters passed into the
method work fine in some orders, but fail in other orders even though I am
using name/value pairs.

Code example follows and any help would really be appreciated.

I have also posted this message in the ms.public.dotnet.framework.clr
newsgroup.

Rgds

Steve

//Class that has a static method with 3 parameters.
public class TestClass
{
    public static bool TestMethod(string a,string b,string c)
    {
        //do stuff
        return true;
    }
}

//Code that calls the TestMethod using InvokeMethod
Type t = typeof(TestClass);

//in the two examples below, a should always map to x, b to y, and c to z,
but for some reason they don't. Out of the 6 possible orders, 4 succeed and
2 fail.

//this call works
t.InvokeMethod("TestMethod",BindingFlags.InvokeMethod,null,null,new
object[3]{"x","y","z"},null,null,new string[3]{"a","b","c"});
//yet this one doesn't
t.InvokeMethod("TestMethod",BindingFlags.InvokeMethod,null,null,new
object[3]{"z","x","y"},null,null,new string[3]{"c","a","b"});



Relevant Pages