Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

visual studio - Edit and Continue: "Changes are not allowed when..."

Even if I create a clean WinForms project, Edit and Continue doesn't work and gives me the error:

Changes are not allowed when the debugger has been attached to an already running process or the code being debugged was optimized at build or run time.

  1. Edit and Continue option is checked in Tools → Options → Debugging.
  2. Optimization is not enabled.
  3. Seems like there is no any managed profiler set up.
  4. I am running in Debug mode
  5. I am running on x64 CPU and Windows XP 32-bit, but setting platform target to x86 rather than AnyCpu doesn't help.
  6. Repairing Visual Studio installation doesn't help.

I also found this article on MSDN website:

Unsupported Scenarios

Edit and Continue is not available in the following debugging scenarios:

  • Debugging on Windows 98.

  • Mixed-mode (native/managed) debugging.

  • SQL debugging.

  • Debugging a Dr. Watson dump.

  • Editing code after an unhandled exception, when the "Unwind the call stack on unhandled exceptions" option is not selected.

  • Debugging an embedded runtime application.

  • Debugging an application with Attach to rather than running the application with Start from the Debug menu.

  • Debugging optimized code.

  • Debugging managed code when the target is a 64-bit application. If you want to use Edit and Continue, you must set the target to x86. (Project Properties, Compile tab, Advanced Compiler setting.).

  • Debugging an old version of your code after a new version failed to build due to build errors.

But I can answer "No" to every item in this list.

It worked before, but several days ago it stopped working, and I don't know what could be the reason.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Other Applicable Solutions

Below is an incomplete, unordered list of possible solutions to try if you* are trying to fix Edit & Continue quickly.

  • Make sure you are in Debug Mode
  • Make sure you're not launching a mixed mode process
  • Try to set the CPU target to x86 rather than AnyCPU (on x64 machines)
  • Uncheck the Optimize Code checkbox for Debug Mode in Project Properties->Debug
  • Uncheck Enable Optimizations in Advanced Compiler Settings
  • (ASP.NET) Check nightcoder's answer if it is the case
  • (ASP.NET) Check this answer (by matrixugly) if it is the case
  • (ASP.NET) Ensure you have Edit and Continue enabled on the Web tab (vs2010)
  • (ASP.NET) Go to Properties > Web > Servers, and make sure that Enable and continue is checked under Use Visual Studio Development Server.
  • (ASP.NET WebAPI) Make sure you've stopped in the Controller's method using a breakpoint, before trying to edit it.
  • (vs2017) Go to Tools > Options > Debugging and uncheck (deselect) 'Edit and Continue'. This is actually the opposite of the 'conventional' advice (see some other points in this post). It does not allow you to actually make changes in your running program (i.e. it does not hot-swap the code changes that you make) - it simply allows you to edit your code (i.e. it prevents that annoying message and "locking" your editor).
  • Go to Tools > Options > Debugging > General and make sure Require source files to exactly match the original version is unchecked.
  • Check Enable Windows debug heap allocator (Native only) [VS Community 2017]
  • Are you using Microsoft Fakes? It inhibits Edit & Continue.
  • Kill all the *.vshost.exe instances by selecting End Process Tree in the Task Manager. VS will regenerate a correct instance.
  • Remove all the breakpoints with Debug->Delete All Breakpoints
  • Enable and Continue exists in both the Tools > Options > Debugging menu and also in the Project Settings. Be sure to check both places. edit & Continue is not supported with the extended Intellitrace setting.
  • Be sure Debug Info in Project Properties > Build > Advanced > Output > Debug Info is set to Full
  • Some plugin may be interfering. Check by disabling/uninstalling and then trying again the other solutions.
  • If you're not paying enough attention, the error you get while trying to fix this may change to something else that is easier to diagnose. E.g. A method containing a lambda expression cannot support edit and continue.
  • Make sure the System variable COR_ENABLE_PROFILING is not set to 1. Some profilers set this when installing and leave it like that after uninstalling. Open a command prompt and type set to quickly check it your system is affected, if so remove the variable or set it to 0:

    • In Windows 8 and above, search for System (Control Panel).
    • Click the Advanced system settings link.
    • Click Environment Variables.
    • Remove COR_ENABLE_PROFILING
  • Be aware of unsupported scenarios (as reported in the question) and that unsupported edits.


* by 'you', I mean the visitor of the page who is hammering his head on a keyboard to find The solution.


Feel free to edit this answer to add your workaround if not listed here!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...