c# - Why is TargetInvocationException treated as uncaught by the IDE? -


i have code using reflection pull property values object. in cases properties may throw exceptions, because have null references, etc.

object result; try {     result = propertyinfo.getvalue(target, null);  } catch (targetinvocationexception ex) {     result = ex.innerexception.message; } catch (exception ex) {     result = ex.message; } 

ultimately code works correctly, when running under debugger:

when property throws exception, ide drops debugger if exception uncaught. if hit run, program flows through , exception comes out targetinvocationexception real exception in innerexception property.

how can stop happening?

this seems "by design". happens have menu toolsoptionsdebugginggeneralenable code enabled.

as how to: break on user-unhandled exceptions states:

the debugexceptions dialog shows additional column (break when exception user-unhandled) when "enable code" on.

essentially means whenever exception leaving boundary of code (and in case, falls through down .net framework reflection code), visual studio breaks because thinks exception has left user code. doesn't know return user code later in stack.

so there 2 workarounds: disable just code in menu toolsoptionsdebugginggeneral or remove check box user-unhandled .net framework exceptions in menu debugexceptions dialog.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -