allure-csharp
allure-csharp copied to clipboard
System.Reflection.TargetInvocationException is throwing instead of actual step exception
Consider this code:
[AllureStep("This step should fail")]
public static int FailedStep()
{
var x = 1;
return 1 / (1 - x);
}
[Test]
[AllureName("Should fail on step")]
public void ReturnFail()
{
FailedStep();
}
This test failed with exception:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.DivideByZeroException : Attempted to divide by zero.
but should be failed with System.DivideByZeroException : Attempted to divide by zero.
- Allure version: 2.9.5-preview.1
@unickq Are there any plans to address this issue ? This is especially problematic when trying to handle exception thrown by other step methods: Ex: trying to catch a timeout exception thrown by a WebDriverWait.
Hi, @vladdex What runtime do you use?
@delatrie I'm reproducing this in dotnet 8. Accessing the InnerException property of the TargetInvocationException reveals the actual exception.
Hello, I also faced this same issue, as a workaround, you can have a look at my solution in the discussion section of the Allure organization. It involves creating an aspect around the base aspect to handle this exception and unwrap it. https://github.com/orgs/allure-framework/discussions/2590#discussioncomment-9830924