简体   繁体   English

在VS10中调试时断点没有被击中

[英]Breakpoints not getting hit while debugging in VS10

I am working on a C# and Silverlight project and every once in a while I run into an issue where my breakpoints are no longer getting hit when I debug. 我正在开发一个C#和Silverlight项目,每隔一段时间我遇到一个问题,我的断点在调试时不再受到攻击。 In the editor they are not turning transparent so I know the correct code is loaded and being run. 在编辑器中,它们没有变得透明,因此我知道正确的代码已加载并正在运行。

An example would be: 一个例子是:

I have Value with a getter and setter and it is bound to a control. Value有一个getter和setter和它被绑定到一个控制。 When I put a breakpoint in the setter and I change the value of Value from the control the breakpoint is not getting hit. 当我在setter中放置一个断点并且我从控件中更改Value的值时,断点不会被击中。

I know that an IIS reset fixes this problem but I would like to know the cause. 我知道IIS重置修复了这个问题,但我想知道原因。 Does anybody else find similar behavior? 有没有人发现类似的行为? If anybody would be able to point me in the direction of a possible cause that would be much appreciated. 如果有人能够指出我可能的原因,将非常感激。

There is an option in Visual Studio 2010: Visual Studio 2010中有一个选项:

  • Tools -> Options... 工具 - >选项......
  • Debugging -> General 调试 - >常规
  • "Step over properties and operators (Managed only)" “跨越属性和运营商(仅管理)”

Make sure this isn't checked. 确保未选中此项。 This assumes that the breakpoint is a solid red circle, indicating that VS has found debugging symbols for it. 这假设断点是一个实心的红色圆圈,表示VS已找到它的调试符号。

Alternatively, these elements of code could be decorated with one of various debugging attributes, namely DebuggerStepThroughAttribute , DebuggerNonUserCodeAttribute and DebuggerHiddenAttribute . 或者,这些代码元素可以使用各种调试属性之一进行修饰,即DebuggerStepThroughAttributeDebuggerNonUserCodeAttributeDebuggerHiddenAttribute These may stop the debugger from going into the method, even if a breakpoint is there. 这些可能会阻止调试器进入方法,即使存在断点。

Of course, if the code you are debugging has been optimised, it may look like it's missing lines. 当然,如果您正在调试的代码已经过优化,那么它可能看起来像是缺少行。 I'm not sure what happens if you try to breakpoint a line that has been optimised away. 我不确定如果你试图断开一条已被优化的线路会发生什么。

If the breakpoint has gone hollow (not solid red), then Visual Studio likely cannot find the debugging symbols for the code. 如果断点已经空洞(不是纯红色),则Visual Studio可能无法找到代码的调试符号。

If a reset fixes the issue , perhaps there are differences between the code being debugged and the original source file / symbols, there is an option to make this less strict: 如果重置修复了问题 ,可能是正在调试的代码与原始源文件/符号之间存在差异,可以选择使其不那么严格:

  • Same options area as above. 与上面相同的选项区域。
  • "Require source files to exactly match the original version" “要求源文件与原始版本完全匹配”

Many times i face this problem though while on winforms apps. 很多时候我在winforms应用程序上遇到这个问题。 So simple thing i do is, restart VS prior to Clean and Rebuild the solution. 我做的很简单,就是在清理和重建解决方案之前重新启动VS. Then if nothing works out, just delete the bin directory and let rebuild again. 然后,如果没有任何效果,只需删除bin目录并再次重建。 The last option i do is restart machine. 我做的最后一个选项是重启机器。

Found this question while trying to understand why my own project's breakpoints weren't being hit while trying to run code in vs2010 在试图理解为什么我自己的项目的断点在尝试运行vs2010中的代码时没有被击中时发现了这个问题

Solved it by looking at the project properties under Advanced Compile Options and setting Generate Debug Info to Full. 通过查看“ 高级编译选项”下的项目属性并将“生成调试信息”设置为“完全”来解决此问题。

Might be worth mentioning I jump into code I wish to debug by using the very handy TestDriven.net's "Test With -> Debugger" via a right click on the function I wish to debug. 可能值得一提的是,我通过右键单击我想要调试的函数,使用非常方便的TestDriven.net的“Test With - > Debugger”跳转到我希望调试的代码。

(At least) Two potential causes : Visual Studio options, or ReSharper options (至少)两个可能的原因 :Visual Studio选项或ReSharper选项

Example : if I break at some call like Console.WriteLine(myVar.myProp) , and I also break inside the myProp getter, the breakpoint inside the getter will be completely skipped if the following settings are still turned on. 示例 :如果我在某些调用中断,如Console.WriteLine(myVar.myProp) ,并且我也在myProp getter内部myProp ,如果仍然打开以下设置, 则将完全跳过getter内的断点

For the Visual Studio Options: 对于Visual Studio选项: 在此输入图像描述

And for the ReSharper Options: 对于ReSharper选项: 在此输入图像描述

So, turn these off to avoid datatips from causing your breakpoints to be skipped. 因此,请关闭这些以避免数据提示导致跳过断点。

I've had this problem recently. 我最近遇到过这个问题。 While I did not find the exact cause, a simple fix was to check the app is running in debug mode (as opposed to release) and clean / rebuild the solution. 虽然我没有找到确切的原因,但一个简单的解决方法是检查应用程序是否在调试模式下运行(而不是发布)并清理/重建解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM