"Cannot evaluate expression because the code of the current method is optimized" in Visual Studio 2010

Tony_Henrich picture Tony_Henrich · Aug 10, 2010 · Viewed 118k times · Source

I am using Visual Studio 2010 in debug mode and I have "optimize code" unchecked. I can't quick watch (or hover on) any variable in the debugger. I get this error "Cannot evaluate expression because the code of the current method is optimized".

Even a line like: int i = -3, doing a quick watch on i, I get "Cannot obtain value of local or argument 'i' as it is not available at this instruction pointer, possibly because it has been optimized away."

This link referenced in a similar question doesn't seem to apply.

Is there a setting I am missing?

Answer

Tony_Henrich picture Tony_Henrich · Aug 10, 2010

While the project was in debug mode, the solution was not. When I changed it, it worked.