Cannot obtain value because it has been optimized away

后端 未结 4 726
鱼传尺愫
鱼传尺愫 2021-02-07 11:50

I have a problem with debugging... All of a sudden I can\'t see the values of most variables while debugging. I\'ve managed to get two different messages in the Immediate Window

相关标签:
4条回答
  • 2021-02-07 12:30

    For anyone else who was stumped on this, you may be making the same simple mistake I was: my build mode was set to Release from another project I had to build for release earlier in the day. Flip it back to Debug; problem solved.

    0 讨论(0)
  • 2021-02-07 12:38

    After making the changes listed by codekaizen and isanka thalagala, do not forget to clean, rebuild and publish to make the changes effective.

    0 讨论(0)
  • 2021-02-07 12:42

    The best way I've found to convince the JIT compiler not to optimize the code is to use an INI file with the name of the assembly in the same folder the assembly is in with the contents:

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

    Note that it has to be the name of the assembly, not the name of the process EXE (unless it is the EXE assembly you want to debug). E.g. if you have an assembly MyCode.dll the INI file name would be MyCode.ini.

    Here are some slides from a presentation on .Net debugging which show the difference:

    With Optimization:

    Without Optimization:

    0 讨论(0)
  • 2021-02-07 12:45

    Go to -> Project Properties -> under Build -> set "Optimize Code" checkbox Unchecked.

    Also, Under Project Properties -> Build -> Advanced -> set the "Debug Info" dropdown to "Full" in the Options

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