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

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

    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 false 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.

提交回复
热议问题