visual-studio 为什么 VS2010 调试器不会在我的断点处停止?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3551413/
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
Why doesn't VS2010 debugger stop at my breakpoints?
提问by PICyourBrain
I am working on a C#.NET class library project in VS2010. In my project settings -> debug settings, I have the project set to start an external program (C:\Windows\SysWOW64\wscript.exe) which runs a very simple jscript file (test.js). The script simply creates an instance of the class and calls one of it's methods.
我正在 VS2010 中处理 C#.NET 类库项目。在我的项目设置 -> 调试设置中,我将项目设置为启动一个外部程序 (C:\Windows\SysWOW64\wscript.exe),该程序运行一个非常简单的 jscript 文件 (test.js)。该脚本只是创建类的一个实例并调用它的方法之一。
The problem is when I start debugging, VS2010 does not stop at any of my breakpoints. If I open up the exact same project in VS2008 it does stop at the break points. Is there a new setting somewhere that is preventing the breakpoints from being hit? Has anyone else ran into this issue?
问题是当我开始调试时,VS2010 不会在我的任何断点处停止。如果我在 VS2008 中打开完全相同的项目,它会在断点处停止。某处是否有新设置可以防止断点被击中?有没有其他人遇到过这个问题?
采纳答案by Paul N
To solved this problem by creating a config file for the application which is using the component to debug with the following data:
通过为应用程序创建一个配置文件来解决这个问题,该应用程序使用该组件使用以下数据进行调试:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
With this file you tell the debugger to use the right runtime version for debugging (it seems the debugger uses version 4.0 by default).
使用此文件,您可以告诉调试器使用正确的运行时版本进行调试(似乎调试器默认使用 4.0 版)。
回答by JaredPar
My first check would be to disable "Just My Code"
我的第一个检查是禁用“仅我的代码”
- Tools -> Options
- Debugger
- Uncheck "Enable Just My Code"
- 工具 -> 选项
- 调试器
- 取消选中“仅启用我的代码”
Try the scenario again.
再次尝试该场景。
回答by JanBorup
I have a tried a whole day to find out why I couldn't debug my visual studio 2012 console application, and the answer was embarrassing.
我试了一整天想找出为什么我无法调试我的visual studio 2012控制台应用程序,答案很尴尬。
I was running it in "RELEASE" mode.
我在“发布”模式下运行它。
Sometimes the obvious is the hard to find.
有时显而易见的是很难找到。
回答by Santhosh Legent
Close the Visual Studio IDE and Open it.Now it will work. For me it also face the same issue. I used this way to overcome
关闭 Visual Studio IDE 并打开它。现在它将起作用。对我来说,它也面临同样的问题。我用这种方法来克服
回答by Ken
I had a "Rebuilt" VS2013 project that I couldn't debug (no symbols). Finally, I saw Optimization was checked (Project->Properties->Build). I unchecked it and Rebuilt. Symbols loaded finally. My two cents, only use (compile) Optimization when absolutely necessary.
我有一个无法调试的“重建”VS2013 项目(没有符号)。最后,我看到优化被检查(Project->Properties->Build)。我取消选中它并重建。最后加载符号。我的两分钱,只有在绝对必要时才使用(编译)优化。
回答by David Goshadze
While I can't answer why it happens, I can provide you with workaround.
虽然我无法回答为什么会发生这种情况,但我可以为您提供解决方法。
Include
using System.Diagnostics;At the very beginning of your code (Class constructor for instance) place the following lines:
#if (DEBUG) while(!Debugger.IsAttached); Debugger.Break(); #endifStart debugging.
- Menu Tools→Attach to Process
- Attach to your process.
包括
using System.Diagnostics;在代码的最开始(例如类构造函数)放置以下几行:
#if (DEBUG) while(!Debugger.IsAttached); Debugger.Break(); #endif开始调试。
- 菜单工具→附加到进程
- 附加到您的流程。
breakpoint should trigger in your code. Other breakpoints should trigger as well.
断点应在您的代码中触发。其他断点也应该触发。
回答by Jens Mose Pedersen
I had a problem with misplaced breakpoints in my native c++ code. The reason was I had been editing the code so some line ends in the code was not \r\n. It was not possible to see in the code unless you searched for \r\n. After inserting the proper line ends \r\n the debugger worked.
我在我的本机 C++ 代码中遇到了错位断点的问题。原因是我一直在编辑代码,所以代码中的某些行结尾不是 \r\n。除非您搜索 \r\n,否则无法在代码中看到。插入正确的行结束后\r\n 调试器工作。
回答by razzy
I encountered the similar issue but its in a CLR project. I had some old c++ syntax in the CLR project. For me after I enabled 'Use managed compatibility mode' in Tools>options>Debugging>General it started to hit the break points.
我遇到了类似的问题,但它在 CLR 项目中。我在 CLR 项目中有一些旧的 c++ 语法。对我而言,在“工具”>“选项”>“调试”>“常规”中启用“使用托管兼容模式”后,它开始遇到断点。
回答by stuartdotnet
Could be a number of reasons. Usually it's because you're trying to debug against the wrong version.
可能有多种原因。通常是因为您试图针对错误的版本进行调试。
These actions work about 80% of the time.
这些操作大约有 80% 的时间起作用。
- Get the latest code
- Clean
- Rebuild
- Restart IIS
- Try again
- 获取最新代码
- 干净的
- 重建
- 重启 IIS
- 再试一次
If no good, go to Debug > Windows > Modules and if the relevant dll is there, right click it and load symbols.
如果不好,请转到调试> Windows > 模块,如果相关的 dll 存在,请右键单击它并加载符号。
If it's not in the list, try running the code anyway. Sometimes even though it says the breakpoint will not be hit, it's only because the dll is not loaded until you enter a scenario that needs it. Try the scenario that depends on the dll, and it may just hit the breakpoint anyway.
如果它不在列表中,无论如何都要尝试运行代码。有时即使它说不会命中断点,也只是因为在您进入需要它的场景之前不会加载 dll。尝试依赖于 dll 的场景,无论如何它可能会遇到断点。
Oh one more idea, restart your browser. You might have something cached from an older dll.
哦,还有一个想法,重新启动浏览器。您可能从较旧的 dll 中缓存了某些内容。
回答by Marko Bonaci
If the reason is wrong .NET runtime version (which was my problem), instead of creating configuration file you can simply choose the right version in the Attach to processdialog.
如果原因是 .NET 运行时版本错误(这是我的问题),则无需创建配置文件,您只需在“附加到进程”对话框中选择正确的版本即可。
In the dialog, next to Attach toclick on Selectand switch from Automatically...to Debug these code typeswhere you should check the right version.
在对话框中,在“附加”旁边单击“选择”并从“自动...”切换到“调试这些代码类型”,您应该在其中检查正确的版本。
If this was your problem also, then you probably had "Symbols not loaded" message on your breakpoints. Immediately after selecting the right version you should see that this error is no longer reported.
如果这也是您的问题,那么您的断点上可能有“符号未加载”消息。选择正确的版本后,您应该立即看到不再报告此错误。

