Go to Project Properties and under Build Make sure that the "Optimize Code" checkbox is unchecked.
Also, set the "Debug Info" dropdown to "Full" in the Advanced Options (Under Build tab).
Also In VS 2015 Community Edition
go to Debug->Options or Tools->Options
and check Debugging->General->Suppress JIT optimization on module load (Managed only)
If you compile with optimizations enabled, then many variables will be removed; for example:
SomeType value = GetValue();
DoSomething(value);
here the local variable value
would typically get removed, keeping the value on the stack instead - a bit like as if you had written:
DoSomething(GetValue());
Also, if a return value isn't used at all, then it will be dropped via "pop" (rather than stored in a local via "stloc", and again; the local will not exist).
Because of this, in such a build the debugger can't get the current value of value
because it doesn't exist - it only exists for the brief instant between GetValue()
and DoSomething(...)
.
So; if you want to debug... don't use a release build! or at least, disable optimizations while you debug.
In visual Studio 2017 goto Debug->Option then check Debugging->general-> and check this option
I just ran into this and I was running under Release
build configuration instead of Debug
build configuration. Once I switched back to Debug
my variable showed in the watch again.
When I was faced with the same problem I just had to clean my solution before rebuilding. That took care of it for me.
I have faced the same issue and the solution for me is change Solution Configuration
from Release
to Debug
. Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With