vendredi 11 janvier 2019

Reflection of internal static method in non static class

Im trying to use reflection to call an internal static method thats part of a non static class.

Example of the class:

public class Example
{
    internal static string ExampleMethod(string input, out string output)
    {
        return string.Empty;
    }
}

My attempt at reflection:

var dynMethod = typeof(Example).GetMethod("ExampleMethod", BindingFlags.NonPublic | BindingFlags.Static);

This line is throwing the exception:

Exception has been thrown by the target of an invocation
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)





Aucun commentaire:

Enregistrer un commentaire