简体   繁体   English

防止调试器在已编译的LambdaExpression中停止异常

[英]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. 在我的程序中,我创建了动态lambda表达式,然后将它们编译为委托。 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. 我已启用“仅启用我的代码”,并将[DebuggerNonUserCode]属性应用于LambdaExpression的创建,编译和调用位置。 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. 但是因为在Debug> Exceptions> Common Language Runtime Exceptions中,Throwd复选框被选中,Visual Studio总是在错误时停止,这对开发人员来说是一个很大的不便。

It seems that [DebuggerNonUserCode] should somehow be applied to the compiled delegate, but how? 似乎[DebuggerNonUserCode]应该以某种方式应用于已编译的委托,但是如何? 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. 但是,可能的建议是转到“ Debug > Exceptions的“异常”菜单,然后选择要具体打破的异常。 If your expressions tend to throw exceptions of specific kinds, you can just disable breaking on those exceptions. 如果您的表达式倾向于抛出特定种类的异常,则可以禁用对这些异常的中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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