views:

143

answers:

2

I have a bit of code which is calling the InvokeMember method on a Type. This is fine and works however if an exception occurs within the member being invoked then the debug jumps to where I am calling InvokeMember as opposed to the inner exception.

Is it possible to get around this so that the code debugs as expected?

A: 

It is actually not possible, because the reflection classes invoke the methods in a different way than you would expect. It is very indirect and if you actually run through the debugger, you would see the different lines of code being executed inside the library files and you will not understand anything worth while from them.

Xinxua
+1  A: 

Yes it is possible. Press Ctrl-Alt-E in Visual Studio to bring up theExceptions dialog box. Check the box to break on Thrown Common Language Runtime Exceptions (not just User-unhandled ones). Now debug your code and you will find it breaks inside your reflection-invoked method.

David M
Fantastic! Works perfectly.
Craig Bovis