samedi 6 juin 2020

Call a static method of a static class using reflection

i trying to call a static method like this :

Assembly myAssembly = Assembly.LoadFrom(filePath);
Type Mytype = myAssembly.GetType("MyClass");
string returnedValue = Mytype.GetMethod("MyMethod").Invoke(null, null).ToString();
MessageBox.Show(returnedValue);

but i get this error : Object reference not set to an instance of an object.

internal static class MyClass
{
internal static string MyMethod(int param1)
{
return "HI"
}
}

Please help me to resolve this problem, regards.





Aucun commentaire:

Enregistrer un commentaire