简体   繁体   English

Visual Studio 断点警告

[英]Visual Studio Breakpoint Warning

When debugging my code, I often throw breakpoints in to check the values of local variables to make sure everything is on the right track.在调试我的代码时,我经常会抛出断点来检查局部变量的值,以确保一切都在正确的轨道上。

Lately, when I make changes to my code and recompile, all my breakpoints turn into the outline of a circle (instead of a full red circle) and it gives me an error that reads;最近,当我对代码进行更改并重新编译时,我的所有断点都变成了一个圆圈的轮廓(而不是一个完整的红色圆圈),它给了我一个错误,上面写着;

The breakpoint will not currently be hit.当前不会命中断点。 No executable code is associated with this line.没有可执行代码与此行相关联。 Possible causes include: conditional compilation or complier optimizations.可能的原因包括:条件编译或编译器优化。

What's strange about this issue is that I can simply remove and add the breakpoint and everything will work completely fine.这个问题的奇怪之处在于我可以简单地删除和添加断点,一切都会正常工作。

I am not using any type of conditional compilation or complier optimizations.我没有使用任何类型的条件编译或编译器优化。 Does anyone know what this means or how to fix this?有谁知道这意味着什么或如何解决这个问题? It gets quite annoying replacing 10-12 breakpoints each time I compile.每次编译时替换 10-12 个断点会很烦人。

This can happen for a few reasons这可能有几个原因

  • The code the debugger is using is different from the code that the application is running调试器使用的代码与应用程序运行的代码不同
  • The pdb file that the debugger is using is different from the code that the application is running调试器使用的 pdb 文件与应用程序正在运行的代码不同
  • The code the application is running has been optimized and debug information has been stripped out.应用程序正在运行的代码已经过优化,调试信息已被剥离。
  • The code in which you have breakpoints on hasn't been loaded into the process yet (assuming the things above are not the culprits)您在其中设置断点的代码尚未加载到进程中(假设上述内容不是罪魁祸首)
  • If you are attaching the debugger, pay attention to what .net framework it's attaching to (i've had issues with it using .net 4 when code was all .net 2.0)如果要附加调试器,请注意它附加到的 .net 框架(当代码全部为 Z2D50972FCECD376129545507F106 时,我在使用 .net 4 时遇到了问题)
  • The assembly you have is also in the GAC.您拥有的程序集也在 GAC 中。 This might happen if say you installed your program so you could debug it, but the installer put the dll in the GAC.如果说您安装了程序以便调试它,但安装程序将 dll 放入 GAC,则可能会发生这种情况。
  • Remove the reference and re-add it (thanks to forsvarir ).删除引用并重新添加它(感谢forsvarir )。 Typically this occurs when the project that is referenced is not in the solution, and VS will copy the dll from the bin directory of another project.通常,当引用的项目不在解决方案中时会发生这种情况,VS 将从另一个项目的 bin 目录中复制 dll。 You will know this was the issue when you try to re-add the reference, and can't find the project:)当您尝试重新添加引用并且找不到项目时,您会知道这是问题所在:)

It's pretty tough to figure out what's going on here, but i would suggest using the fusion log viewer to see what is being loaded and where it's being loaded from and then you can look at the dll and see if it's old code, etc.很难弄清楚这里发生了什么,但我建议使用融合日志查看器查看正在加载的内容以及从哪里加载,然后您可以查看 dll 并查看它是否是旧代码等。

Check the project settings检查项目设置

Make sure you don't check the code optimize option, and make sure debug symbols are checked.确保您没有检查代码优化选项,并确保检查了调试符号。

调试

Notice that when you change the configuration other settings might change as well and you might not see.请注意,当您更改配置时,其他设置也可能会更改,而您可能看不到。 Make sure the values are correct for the configuration you are attempting to compile.确保值对于您尝试编译的配置是正确的。


Delete the output files删除 output 文件

Physically delete all generated DLLs, PDBs and EXEs.物理删除所有生成的 DLL、PDB 和 EXE。 Then compile again to generate the files.然后再次编译生成文件。 Sometimes Visual Studio can "get lost" and "forget" to overwrite the output files when you build your solution.有时,在构建解决方案时,Visual Studio 可能会“迷路”和“忘记”覆盖 output 文件。


Restart your computer重启你的电脑

It usually solves 99% of problems.它通常可以解决 99% 的问题。 I already had some issues with Visual Studio and restarting it or the computer solved the problem.我已经遇到了 Visual Studio 的一些问题并重新启动它或计算机解决了问题。

I know this is an old post but still timely enough as I was looking for any other reason I might be getting this problem.我知道这是一篇旧帖子,但仍然足够及时,因为我正在寻找可能遇到此问题的任何其他原因。

That being said you also might want to check the "Temporary ASP.NET Files" in your c:\Windows\Microsoft.NET\[Frameworks] directories if you are creating a web application as these files are often the cause in my experience.也就是说,如果您正在创建 Z2567A5EC9705EB7AC2C984033E06 应用程序中的 Z2567A5EC9705EB7AC2C984033E06 目录

Adding this response to the old thread in case someone like me is tracking down this mystery in an older ASP.Net application.将此响应添加到旧线程,以防像我这样的人在旧的 ASP.Net 应用程序中追踪这个谜团。 I had one Webform code-behind which did not respond to breakpoints with the "...no executable code..." debugger warning.我有一个 Webform 代码隐藏,它没有响应带有“......没有可执行代码......”调试器警告的断点。 It was doing my head in as all of the other pages were working fine.当所有其他页面都运行良好时,它让我很头疼。 I'd done the clean, rebuild, purged the temporary ASP.Net files, no joy.我已经完成了清理、重建、清除临时 ASP.Net 文件,但没有任何乐趣。

The culprit with this file was the inclusion of several #ExternalSource directives surrounding some of the member variable declarations.这个文件的罪魁祸首是包含几个围绕一些成员变量声明的#ExternalSource 指令。 Once those were removed and the project rebuilt, the break point behavior was restored.一旦这些被删除并重建项目,断点行为就恢复了。 Those ExternalSource lines were appearing in the generated section of the code-behind.那些 ExternalSource 行出现在代码隐藏的生成部分中。 Not sure why they were there.不知道他们为什么在那里。

The use of the precompiler directive #line appears to affect the breakpoints behavior as well, as I've just discovered.正如我刚刚发现的那样,使用预编译器指令#line 似乎也会影响断点行为。

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

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