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.

abenci
  • 8,422
  • 19
  • 69
  • 134
  • Release config wont even initialize variables which are not used. Do something with your variable and check again. – Szer Jul 23 '15 at 07:05
  • 1
    @Szer: I'm talking about used variables, I'm comparing what I see in Visual Studio 2013 and 2015. – abenci Jul 23 '15 at 07:06
  • I didn't know this was possible in release mode in any version of VS. – MikeS159 Jul 23 '15 at 08: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. – Lasse V. Karlsen Aug 24 '15 at 08:06
  • Possible duplicate of [this](http://stackoverflow.com/questions/28730100/visual-studio-2015-debugging-cant-expand-local-variables/32143294#32143294). – ilCosmico Oct 16 '15 at 12:16
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jan 22 '16 at 12:43

2 Answers2

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

DeJaVo
  • 3,091
  • 2
  • 17
  • 32
  • Why should be ever possible to watch a variable in Release Mode? – abenci Jul 23 '15 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 Jul 23 '15 at 21:21
3

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

abenci
  • 8,422
  • 19
  • 69
  • 134