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 \"Canno
I had mixed c++/cli mfc extension dlls, that were optimised even if debug configuration (seen from VS 2017 Modules window). As previous answer suggested I changed "In VS2013 go to: Tools -> Options -> Debugging -> General and enable 'Use managed compatibility mode'. This disables the new function evaluation behavior." That settings find also in VS 2017.
But that was not enough, so I also copied the UseDebugLibraries setting from another MFC app's project file to extension dll project file.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
...
<UseDebugLibraries>true</UseDebugLibraries>
Then rebuild and that fixed the problem.
When you see the "Cannot evaluate expression because the code of the current method is optimized." message after issuing a Debugger.Break()
statement then please make sure you press F10 to step to the next statement.
Once stepped to the next statement, and assuming you are running a Debug build, this message should disappear.
I had the same problem while debugging a class library from a testbed web app. I was referencing the release version in the testbed and that was set to be optimised in the class library properties.
Un-ticking the optimise code checkbox for the release version in the class library properties, just while I am writing it, has solved the issue.
I had the same issue in VS 2010. Cleaned-up and rebuild the solution and it worked.