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

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

    It sounds like you are debugging an optimised / release build, despite having the optimised box un-checked. Things you can try are:

    • Do a complete rebuild of your solution file (right click on the solution and select Rebuild all)
    • While debugging open up the modules window (Debug -> Windows -> Modules) and find your assembly in the list of loaded modules. Check that the Path listed against your loaded assembly is what you expect it to be, and that the modified timestamp of the file indicates that the assembly was actually rebuilt.
    • The modules window should also tell you whether or not the loaded module is optimised or not - make sure that the modules window indicates that it is not optimised.

    If you cant't see the Modules menu item in the Debug -> Windows menu then you may need to add it in the "Customise..." menu.

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

    Try to run in debug mode.If you are running in release mode you will get this message.

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

    I had the same problem. But in my case, the Debuggable attribute was hard coded in the AssemblyInfo.cs file of my project and therefor not (over-)written by compilation. It worked after removing the line specifying the Debuggable attribute.

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

    I had the same problem in VS2008. In my case it was solved via solution-rebuild.

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

    In Visual Studio 2012 enabling the "Managed" option from Tools > Debugging > Just-In-Time worked for me.

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

    Apart from @Kragen mentioned, If you are debugging a web project

    close the visual studio and try deleting the temporary files at C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

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