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

后端 未结 22 540
耶瑟儿~
耶瑟儿~ 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:18

    In VS2013 go to: Tools -> Options -> Debugging -> General and enable 'Use managed compatibility mode'. This disables the new function evaluation behavior.

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

    I had this problem with an F# project that had been here and there between Visual Studio and MonoDevelop, perhaps originating in the latter (I forget). In VS, the optimize box was unchecked, yet optimization certainly seemed to be occuring as far as the debugger was concerned.

    After comparing the XML of the project file against that of a healthy one, the problem was obvious: the healthy project had an explicit <optimize>false</optimize> line, whereas the bad one was missing it completely. VS was obviously inferring from its absence that optimization was disabled, while the compiler was doing the opposite.

    The solution was to add this property to the project file, and reload.

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

    One other thing that you may do is, create a file with the same name as the dll that is optimized but with ini extension and add the following to it:

    [.NET Framework Debugging Control]
    GenerateTrackingInfo=1
    AllowOptimize=0

    This will tell the JIT not to optimize your variables.

    Note that you still need the pdb, so you will end up with something like this: yourDll.dll yourDll.pdb yourDll.ini

    This works specially well in scenarios when you don't have access to re-generate the dlls with debug option.

    http://www.hanselman.com/blog/DebugVsReleaseTheBestOfBothWorlds.aspx

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

    If you're trying to debug an ASP.NET project, ensure that the project's Properties > Web > Servers dropdown is set to "IIS Express" (in addition to checking everything else here).

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

    I had this issue when I was using VS 2010. My solution configuration has (Debug) selected. I resolved this by unchecking the Optimize Code property under project properties. Project (right Click)=> Properties => Build (tab) => uncheck Optimize code

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

    I started receiving this message when I migrated to Visual Studio 2017. None of the ideas on this page that I tried worked for me. On another post I found this suggestion and it DID work - remove:

    [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
    

    ...from your AssemblyInfo file.

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