简体   繁体   中英

Prevent debugger from stopping on an Exception in a Compiled LambdaExpression

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM