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

后端 未结 22 539
耶瑟儿~
耶瑟儿~ 2020-12-23 08:59

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

相关标签:
22条回答
  • 2020-12-23 09:22

    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.

    0 讨论(0)
  • 2020-12-23 09:25

    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.

    0 讨论(0)
  • 2020-12-23 09:25

    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.

    0 讨论(0)
  • 2020-12-23 09:27

    I had the same issue in VS 2010. Cleaned-up and rebuild the solution and it worked.

    0 讨论(0)
提交回复
热议问题