1

I've just upgraded to Visual Studio 2015 RTM. Why I can't watch variable values in release mode when I'm stopped on a breakpoint? It was possible in previous Visual Studio versions.

EDIT: I'm talking about used variables, of course.

6
  • Release config wont even initialize variables which are not used. Do something with your variable and check again.
    – Szer
    Commented Jul 23, 2015 at 7:05
  • 1
    @Szer: I'm talking about used variables, I'm comparing what I see in Visual Studio 2013 and 2015.
    – abenci
    Commented Jul 23, 2015 at 7:06
  • I didn't know this was possible in release mode in any version of VS.
    – MikeS159
    Commented Jul 23, 2015 at 8:09
  • Both the compiler and the JITter was changed with the new version of Visual Studio and .NET, there may be things that changed drastically under the hoot in terms of optimizations and register usage. Commented Aug 24, 2015 at 8:06
  • Possible duplicate of this.
    – ilCosmico
    Commented Oct 16, 2015 at 12:16

2 Answers 2

4

According to Microsoft support it is not possible:

If I'm reading the solution summary correctly, it looks like you're building Release, rather than Debug. In Release, some locals will be optimized away and will not be available during debugging. In your particular example, it looks like it would be easy to optimize away "roles" by inlining its value into the return statement.

If you need to know the value of that variable, it should be visible after you switch to the Debug configuration.

Thanks, Andrew Casey C#/VB Developer

Source: https://connect.microsoft.com/VisualStudio/feedback/details/1038150/visual-studio-2015-debugger-doesnt-recognize-a-variable

2
  • Why should be ever possible to watch a variable in Release Mode?
    – abenci
    Commented Jul 23, 2015 at 20:57
  • 1
    In case the variable wasn't optimized by compiler and you would like to debug it. You can simulate such case by disabling compiler optimization but it is a trade-off between "sticking exactly to the code I wrote" versus "transforming my code into something more efficient", where the latter means there will be discrepancies between what the source code says and what actually happens when you run or debug the app.
    – DeJaVo
    Commented Jul 23, 2015 at 21:21
3

I've solved unchecking Project Properties -> Build -> Optimize Code option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.