Tuesday, June 23, 2009

Visual Studio C# debug problem

This is not very helpful: I am hitting an Debug.Assert in some C# code (I am running in debug mode). When I want to look any local variable in the method I see:

cannot evaluate expression because the code of the current method is optimized

It has to do with the Assert. After rewriting as an if statement so I can place a breakpoint I can inspect all variables.

Others have reported the same: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=278033. The answer seems somewhat a cop-out: Closed (Not Reproducible).

I have seen similar issues with Delphi. This is always annoying: when you are debugging you want to focus on the problem at hand, and such debugger bugs suddenly make you pay attention to other things.