Why is TargetInvocationException treated as uncaught by the IDE?

This seems to be “by design”. What happens is that you likely have menu ToolsOptionsDebuggingGeneralEnable Just My Code enabled.

As How to: Break on User-Unhandled Exceptions states:

The DebugExceptions dialog shows an additional column (Break when an exception is User-unhandled) when “Enable Just My Code” is on.

Essentially this means that whenever the exception is leaving the boundary of your code (and in this case, it falls through down to the .NET framework reflection code), Visual Studio breaks because it thinks that the exception has left the user code. It doesn’t know that it will return into the user code later in the stack.

So there are two workarounds: Disable Just My Code in menu ToolsOptionsDebuggingGeneral or Remove the check box from the User-unhandled .NET Framework exceptions in menu DebugExceptions dialog.

Leave a Comment