I'm using a public static class and static method with its parameters:
public static class WLR3Logon
{
static void getLogon(int accountTypeID)
{}
}
Now I am trying to fetch the method with its parameters into another class and using the following code:
MethodInfo inf = typeof(WLR3Logon).GetMethod("getLogon",
BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
int[] parameters = { accountTypeId };
foreach (int parameter in parameters)
{
inf.Invoke("getLogon", parameters);
}
But its giving me error
"Object reference not set to an instance of an object."
Where I'm going wrong.
This problem got solved by using the following approach:
There are many problems here
make your method
public
. It should work after thatYour method is private as you have not explicitly declared an access modifier. You have two options to make your code work as intended:
public
.BindingFlags.NonPublic
in theGetMethod
call