vendredi 28 juin 2019

MethodInfo.Invoke() suppresses Exception

Im using reflection to invoke a method which throws a exception. But this exception is not thrown, neigter i can catch it.
Im invoking by calling:

GetMethod().Invoke(myInstance, new object[] { result });

Where result is of type Object. The called method throws a exception like:

public async Task MyMethod(Object input)
    {
        // do something...
        throw new Exception("Error");

    }

If i dont use a try-catch block, the application continuous as well as if i use one like:

try
{
    GetMethod().Invoke(myInstance, new object[] { result });
    log("everything is ok");
}
catch(Exception e)
{
    log(e.message) 
}

So the expected output should be:

Error

but is

everything is ok





Aucun commentaire:

Enregistrer un commentaire