četvrtak, 8. srpnja 2010.

Exceptions with methods invoked by reflection

If I use reflection to call a method via Invoke and that method throws an exception, the debugger stops on line where the method was called via reflection and not in the faulty method itself

How do I change this, and have the debugger stop on the line of code in error.

Solution:

Check the "Thrown" box for the particular exception -- the debugger will stop where the exception is thrown, before it's caught (and translated) by the Invoke layer.

In Visual Studio 2008, the Debug menu has an Exceptions... option.
When clicking this, it brings up the "Break when an exception is thrown" dialog.