Skip to content

Commit 0dda9bd

Browse files
committed
Manage multi level of TargetInvocationException
1 parent 0592b81 commit 0dda9bd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,12 @@ public object Evaluate(string expression)
16571657
}
16581658
catch (TargetInvocationException exception) when (exception.InnerException != null)
16591659
{
1660-
ExceptionDispatchInfo.Capture(exception.InnerException).Throw();
1660+
Exception exceptionToThrow = exception.InnerException;
1661+
1662+
while (exceptionToThrow is TargetInvocationException && exceptionToThrow.InnerException != null)
1663+
exceptionToThrow = exceptionToThrow.InnerException;
1664+
1665+
ExceptionDispatchInfo.Capture(exceptionToThrow).Throw();
16611666
// Will not go here but need to return something to avoid compilation errors.
16621667
return null;
16631668
}

0 commit comments

Comments
 (0)