Coder Perfect

It is not possible to acquire the value of a local or argument because it is not available at this instruction address, maybe due to optimization.


In the unsafe block, Visual Studio 2010 destroys (there is no other word for it) data in one of the function’s arguments. What could be the source of this error? The debugger displays the following message.

Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away.

Asked by curiousity

Solution #1

Go to Project Properties and select Build from the drop-down menu. Check to see if the “Optimize Code” checkbox is selected.

Set the “Debug Info” dropdown in the Advanced Options to “Full” (Under Build tab).

Answered by Karthik

Solution #2

Also included in the Community Edition of Visual Studio 2015

select Debug->Options or Tools->Options from the menu bar.

additionally, go to Debugging->General-> On module load, disable JIT optimization (Managed only)

Answered by xyq.384.b

Solution #3

Many variables will be eliminated if you compile with optimizations enabled; for example:

SomeType value = GetValue();

Normally, the value of the local variable would be erased, leaving the value on the stack – similar to if you had written:


If a return value isn’t used at all, it will be dropped using the “pop” command (rather than stored in a local via “stloc”, and again; the local will not exist).

As a result, the debugger in such a build will be unable to obtain the current value of value, as it does not exist – it only exists for the brief period between GetValue() and DoSomething() (…).

So… don’t use a release build if you want to debug! or, at the very least, turn off optimizations while you’re debugging.

Answered by Marc Gravell

Solution #4

Go to Debug->Option in Visual Studio 2017, then Debugging->general-> and check this option.

Answered by Zahid Hasan

Solution #5

I recently encountered this issue and discovered that I was using the Release build option rather than the Debug build configuration. My variable reappeared in the watch after I switched back to Debug.

Answered by JabberwockyDecompiler

Post is based on