In my program, I create dynamic lambda expressions and then compile them to delegates. These delegates are then invoked to extract information from my entities. Some of the delegates may throw exceptions, I've caught the exception where I call the delegate. I've enabled "Enable just my code" and applied [DebuggerNonUserCode] attribute to where the LambdaExpression is created, where compiled, and where Called. But because in Debug>Exceptions>Common Language Runtime Exceptions, the Thrown check box is checked, visual studio always stops on the error, which is a major inconvenience for the developers.
It seems that [DebuggerNonUserCode] should somehow be applied to the compiled delegate, but how? Or any other suggestion?
Thanks.
When the debugger breaks, it shows you where the exception was thrown. You can also add or delete exceptions. With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions.
From Visual Studio 2015 and onward, you need to go to the "Exception Settings" dialog ( Ctrl + Alt + E ) and check off the "Common Language Runtime Exceptions" (or a specific one you want i.e. ArgumentNullException ) to make it break on handled exceptions.
As far as I know, you cannot apply attributes to anonymous methods generated using expressions, aside from possibly some horrible messing around with dynamic type generation.
However, a possible suggestion would be to go to the exception menu in Debug > Exceptions
and choose which exceptions you want to break on specifically. If your expressions tend to throw exceptions of specific kinds, you can just disable breaking on those exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With