Consider the following two applications:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
I think the culprit lies within InternalRealCall
method of ExceptionWrapper
. More specifically the following part where we have Action
delegates special cased.
Action action = callback as Action;
if (action != null)
{
action();
}
else
{
// ... removed code ..
obj = callback.DynamicInvoke();
}
Since Action
delegates are called directly the resulting exception is the one you originally thrown. For all other delegate types, since the invocation goes through reflection the exception is wrapped in a TargetInvocationException
.
In conclusion, the differences is a side-effect related to how the provided delegate is called, directly or through reflection.