8

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.

Alireza
  • 5,421
  • 5
  • 34
  • 67
  • 2
    Isn't it stopping on a first change exception? They can be disabled seperatly. – CodingBarfield Jun 25 '12 at 07:07
  • No, it always stops on the error, not just the first time. – Alireza Jun 25 '12 at 07:24
  • 1
    Are you sure the exception is captured somewhere. If there are uncatched exceptions that would crash the application Visual Studio always shows the Exception message. – CodingBarfield Jun 25 '12 at 09:37
  • @CodingBarfield Yes, the exception is caught and does not show up in the detached application, nor dos it appear if I uncheck the checkbox under thrown in Debug > Exceptions. But I need to keep that checkbox checked. – Alireza Jun 27 '12 at 09:42
  • 1
    You can filter first change exceptions for specific exceptions or change the lambda code to something that won't throw exceptions. – CodingBarfield Jun 28 '12 at 06:59
  • Well, I can't change the expressions to avoid exceptions, this requires checking for every possible error source, which will make the expression too complex (in my system, expressions are directly visible by power users, and they should be editable in a near future). But, filtering the exceptions for one debug session is a good idea. – Alireza Jun 30 '12 at 18:43
  • 1
    Even if you could apply that attribute, it seems to have a bug in MSVS 2015 defeating the purpose: http://stackoverflow.com/questions/39382551 – crokusek Sep 08 '16 at 23:52

1 Answers1

1

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.

GregRos
  • 8,667
  • 3
  • 37
  • 63
  • 2
    Well... I may be willing to take those horrible steps. Any pointers to the right resource? Thanks – Alireza Jun 27 '12 at 09:44