C#调用方法参数空引用异常

sno*_*oop 1 c# methods invoke nullreferenceexception winforms

我想从字符串中调用一个方法,但它不允许我null作为参数传递.该方法不需要参数.

private void reconnect_Click(object sender, EventArgs e)
{
   string methodName = "data_load1";

   //Get the method information using the method info class
   MethodInfo mi = this.GetType().GetMethod(methodName);

   //Invoke the method
   mi.Invoke(this, null);
}
Run Code Online (Sandbox Code Playgroud)

data_load方法:

private void data_load1()
{
     this.dataTableAdapter.Fill(this.myDataSet.data);
}
Run Code Online (Sandbox Code Playgroud)

我收到NullReferenceException was unhandledmi.Invoke(this, null);.为什么这不让我传递null参数?

SLa*_*aks 5

mi 一片空白.

要获得私有方法,您需要通过BindingFlags.Instance | BindingFlags.NonPublic.