visual-studio 编辑并继续:“当……时不允许更改”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1010213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Edit and Continue: "Changes are not allowed when..."
提问by nightcoder
Even if I create a clean WinForms project, Edit and Continue doesn't work and gives me the error:
即使我创建了一个干净的 WinForms 项目,“编辑并继续”也不起作用并给我以下错误:
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.
当调试器已附加到已运行的进程或正在调试的代码在构建或运行时进行了优化时,不允许进行更改。
- Edit and Continue option is checked in Tools → Options → Debugging.
- Optimization is not enabled.
- Seems like there is no any managed profiler set up.
- I am running in Debug mode
- I am running on x64 CPU and Windows XP 32-bit, but setting platform target to x86 rather than AnyCpu doesn't help.
- Repairing Visual Studio installation doesn't help.
- 编辑并继续选项在工具 → 选项 → 调试中被选中。
- 未启用优化。
- 似乎没有设置任何托管分析器。
- 我在调试模式下运行
- 我在 x64 CPU 和 Windows XP 32 位上运行,但将平台目标设置为 x86 而不是 AnyCpu 没有帮助。
- 修复 Visual Studio 安装无济于事。
I also found this articleon MSDN website:
我还在MSDN 网站上找到了这篇文章:
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.
不支持的场景
编辑并继续在以下调试场景中不可用:
在 Windows 98 上调试。
混合模式(本机/托管)调试。
SQL调试。
调试 Dr. Watson 转储。
未选择“在未处理的异常上展开调用堆栈”选项时,在未处理的异常之后编辑代码。
调试嵌入式运行时应用程序。
使用“附加到”调试应用程序,而不是使用“调试”菜单中的“启动”运行应用程序。
调试优化的代码。
当目标是 64 位应用程序时调试托管代码。如果要使用“编辑并继续”,则必须将目标设置为 x86。(项目属性,编译选项卡,高级编译器设置。)。
在新版本由于构建错误而无法构建后调试旧版本的代码。
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.
以前可以用,但几天前就停止了,我不知道是什么原因。
采纳答案by Pejvan
I finally got to solve the problem: UNINSTALL Gallio
我终于解决了这个问题:UNINSTALL Gallio
Gallio seems to have quite some many rough edges and it's better to not use MbUnit 3.0 but use the MbUnit 2.0 framework but use the gallio runner, that you are running without installing from the installer (which also installed a visual studio plugin).
Gallio 似乎有很多粗糙的边缘,最好不要使用 MbUnit 3.0,而是使用 MbUnit 2.0 框架,而是使用 gallio runner,您无需从安装程序(也安装了 Visual Studio 插件)安装即可运行。
Incidentally, I had the issue even after "disabling" he Gallio plugin. Only the uninstall solved the problem.
顺便说一句,即使在“禁用”他的 Gallio 插件之后,我也遇到了这个问题。只有卸载解决了问题。
PS. Edited by nightcoder:
In my case disabling TypeMock Isolator(mocking framework) finally helped! Edit & Continue now works!!!
附注。由 nightcoder 编辑:
在我的情况下,禁用 TypeMock Isolator(模拟框架)终于有帮助了!编辑并继续现在有效!!!
Here is the answer from TypeMock support:
这是 TypeMock 支持的答案:
After looking further into the edit and continue issue, and conversing about it with Microsoft, we reached the conclusion it cannot be resolved for Isolator. Isolator implements a CLR profiler, and according to our research, once a CLR profiler is enabled and attached, edit and continue is automatically disabled. I'm sorry to say this is no longer considered a bug, but rather a limitation of Isolator.
在进一步调查编辑并继续问题并与 Microsoft 讨论后,我们得出结论,Isolator 无法解决此问题。Isolator 实现了 CLR 分析器,根据我们的研究,一旦启用并附加了 CLR 分析器,编辑和继续将自动禁用。很抱歉,这不再被视为错误,而是 Isolator 的限制。
回答by beppe9000
Other Applicable Solutions
其他适用的解决方案
Below is an incomplete, unorderedlist 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 x86rather than AnyCPU(on x64 machines)
- Uncheck the Optimize Codecheckbox for Debug Modein Project Properties->Debug
- Uncheck Enable Optimizationsin Advanced Compiler Settings
- (ASP.NET) Check nightcoder's answerif it is the case
- (ASP.NET) Check this answer (by matrixugly)if it is the case
- (ASP.NET) Ensure you have Edit and Continueenabled on the Webtab (vs2010)
- (ASP.NET) Go to Properties > Web > Servers, and make sure that Enable and continueis 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 > Debuggingand 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 runningprogram (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 > Generaland make sure Require source files to exactly match the original versionis 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.exeinstances by selecting End Process Treein the Task Manager. VS will regenerate a correct instance.
- Remove all the breakpoints with Debug->Delete All Breakpoints
- Enable and Continueexists in both the Tools > Options > Debuggingmenu 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 Infoin Project Properties > Build > Advanced > Output > Debug Infois 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_PROFILINGis not set to1. Some profilers set this when installing and leave it like that after uninstalling. Open a command prompt and typesetto quickly check it your system is affected, if so remove the variable or set it to0:- In Windows 8 and above, search for System(Control Panel).
- Click the Advanced system settingslink.
- Click Environment Variables.
- Remove
COR_ENABLE_PROFILING
Be aware of unsupported scenarios(as reported in the question) and that unsupported edits.
- 确保您处于调试模式
- 确保您没有启动混合模式进程
- 尝试将 CPU 目标设置为x86而不是AnyCPU(在 x64 机器上)
- 在项目属性->调试中取消选中调试模式的优化代码复选框
- 在高级编译器设置中取消选中启用优化
- (ASP.NET)如果是这种情况,请检查nightcoder 的答案
- (ASP.NET)如果是这种情况,请检查此答案(通过 matrixugly)
- (ASP.NET) 确保您在Web选项卡上启用了编辑并继续(vs2010)
- (ASP.NET) 转到Properties > Web > Servers,并确保在Use Visual Studio Development Server下选中Enable and continue。
- (ASP.NET WebAPI) 在尝试编辑它之前,请确保您已使用断点在控制器的方法中停止。
- (vs2017) 转到工具 > 选项 > 调试并取消选中(取消选择)“编辑并继续”。这实际上与“传统”建议相反(请参阅本文中的其他一些要点)。它不允许您在正在运行的程序中进行实际更改(即它不会热交换您所做的代码更改)-它仅允许您编辑代码(即它可以防止出现烦人的消息并“锁定”您的编辑器)。
- 转到“工具”>“选项”>“调试”>“常规”,并确保取消选中“要求源文件与原始版本完全匹配”。
- 选中启用 Windows 调试堆分配器(仅限本机)[VS Community 2017]
- 您在使用 Microsoft Fakes 吗?它禁止编辑并继续。
- 通过在任务管理器中选择结束进程树来终止所有*.vshost.exe实例。VS 将重新生成正确的实例。
- 使用Debug->Delete All Breakpoints 删除所有断点
- Enable and Continue存在于Tools > Options > Debugging菜单中,也存在于Project Settings 中。一定要检查两个地方。扩展 Intellitrace 设置不支持编辑和继续。
- 务必调试信息在项目属性>构建>高级>输出>调试信息设置为全
- 某些插件可能会干扰。通过禁用/卸载然后重试其他解决方案来检查。
- 如果您没有给予足够的关注,您在尝试修复此问题时遇到的错误可能会更改为其他更易于诊断的错误。例如,包含 lambda 表达式的方法不能支持编辑和继续。
确保 System 变量
COR_ENABLE_PROFILING未设置为1. 一些分析器在安装时设置了这个并在卸载后保持不变。打开命令提示符并键入set以快速检查您的系统是否受到影响,如果是,请删除变量或将其设置为0:- 在 Windows 8 及更高版本中,搜索系统(控制面板)。
- 单击高级系统设置链接。
- 单击环境变量。
- 消除
COR_ENABLE_PROFILING
* 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!
如果此处未列出,请随时编辑此答案以添加您的解决方法!
回答by viggity
If you're debugging an ASP.NET application, go to properties > web > Servers, and make sure that "enable and continue" is checked under Use Visual Studio Development Server.
如果您正在调试 ASP.NET 应用程序,请转到属性 > Web > 服务器,并确保在“使用 Visual Studio 开发服务器”下选中“启用并继续”。
回答by Amer
I had the same problem. I even re-installed VS 2008 but the problem did not go away. However, when I deleted all the break points then it started to work.
我有同样的问题。我什至重新安装了 VS 2008,但问题并没有消失。但是,当我删除所有断点时,它开始工作。
Debug->Delete All Breakpoints
I think it was happening because I had deleted an aspx page that had break points in its code, and then I created another page with the same name. This probably confused the VS 2008.
我认为这是因为我删除了一个在其代码中有断点的 aspx 页面,然后我创建了另一个具有相同名称的页面。这可能混淆了 VS 2008。
回答by JayW
None of the above solutions worked for me(running on a 64x machine).
以上解决方案都不适合我(在 64x 机器上运行)。
Finally I clicked on 'advanced compiler settings'and UNCHECKED'enable optimizations' and I can now step through code and edit while debugging.
最后,我单击'advanced compiler settings'并取消选中'enable optimizations',现在我可以在调试时单步调试代码并进行编辑。
回答by Protector one
"Edit and Continue", when enabled, will only allow you to edit code when it is in break-mode: e.g. by having the execution paused by an exception or by hitting a breakpoint.
“编辑并继续”,启用后,将只允许您在中断模式下编辑代码:例如,通过异常暂停执行或通过击中断点。
This implies you can'tedit the code when the execution isn't paused! When it comes to debugging (ASP.NET) web projects, this is very unintuitive, as you would often want to make changes between requests. At this time, the code your (probably) debugging isn't running, but it isn't paused either!
To solve this, you can click "Break all" (or press Ctrl+Alt+Break). Alternatively, set a breakpoint somewhere (e.g. in your Page_Loadevent), then reload the page so the execution pauses when it hits the breakpoint, and nowyou can edit code. Even code in .csfiles.
这意味着您不能在执行未暂停时编辑代码!在调试 (ASP.NET) Web 项目时,这是非常不直观的,因为您通常希望在请求之间进行更改。此时,您(可能)调试的代码没有运行,但也没有暂停!
要解决此问题,您可以单击“全部中断”(或按Ctrl+ Alt+ Break)。或者,在某处设置断点(例如在您的Page_Load事件中),然后重新加载页面,以便在遇到断点时执行暂停,现在您可以编辑代码。甚至.cs文件中的代码。
回答by Adam
If your concern is with an ASP.NET app, ensure you have edit and continue enabled on the web tab (vs2010). There was also a separate setting for ASP.NET debugging in earlier versions.
如果您关心的是 ASP.NET 应用程序,请确保您在 Web 选项卡上启用了编辑和继续 (vs2010)。在早期版本中还有一个单独的 ASP.NET 调试设置。
Regards,
问候,
Adam.
亚当。
回答by RAL
I found that even though under project properties build & debug tab are set to Debug and all the other setting are correct I still get the message, however after digging some more under the Build menu select Configurations Manager... and make sure Debug is selected in two places there as well. go figure...how many different places do they need to set debug?????? even though you set Project - Configuration to Debug then under Build - Manager it is not changed so you have change the same setting there as well Project Configuration - seems like a microsoft issue again.......
我发现即使在项目属性下构建和调试选项卡设置为调试并且所有其他设置都是正确的我仍然收到消息,但是在构建菜单下挖掘更多内容后选择配置管理器...并确保选择调试也有两个地方。去看看......他们需要在多少个不同的地方设置调试??????即使您将项目 - 配置设置为调试,然后在构建 - 管理器下它也不会更改,因此您在那里也更改了相同的设置项目配置 - 似乎又是一个微软问题......
回答by KuldeepVerma
This problem is due to Intellitrace setting
这个问题是由于 Intellitrace 设置
If Intellitrace is enabled make sure Intellitrace event only is checked
如果启用了 Intellitrace,请确保仅选中 Intellitrace 事件
Otherwise this will not allow edit and continue..
否则这将不允许编辑并继续..
If you will click on Intellitrace options you will see the warnings.
如果您单击 Intellitrace 选项,您将看到警告。
回答by JaredPar
Couple of things to check
需要检查的几件事
- Make sure your compile is set to Debug vs. Release
- Make sure you're not launching a mixed mode process
- If on a 64 bit machine Make sure to set the CPU target to x86 rather than AnyCPU
- 确保您的编译设置为调试与发布
- 确保您没有启动混合模式进程
- 如果在 64 位机器上确保将 CPU 目标设置为 x86 而不是 AnyCPU
EDIT
编辑
I don't believe this should matter but make sure that the hosting process is enabled for the target platform. Probably won't help.
我认为这无关紧要,但请确保为目标平台启用了托管过程。可能帮不上忙。
If it repros for new projects then it might be something even more subtle. I would try the following.
如果它重新用于新项目,那么它可能会更加微妙。我会尝试以下。
- Backup HKCU:\Software\Wow6432Node\VisualStudio\9.0 (maybe just rename it)
- Delete the same key
- Try the repro again
- 备份 HKCU:\Software\Wow6432Node\VisualStudio\9.0(也许只是重命名)
- 删除相同的密钥
- 再次尝试重现

