如果多个文件具有相同的名称,则Visual Studio断点会在错误的源文件(或多个文件)中断 [英] Visual Studio breakpoints break in the wrong source file (or multiple files simultaneously) if multiple files have the same name

查看:211
本文介绍了如果多个文件具有相同的名称,则Visual Studio断点会在错误的源文件(或多个文件)中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的一个团队项目中,在文件中设置断点(如 IdeasController.cs )将导致调试器行为不规则,如果有另一个文件同名的解决方案。我已经在几个开发人员的工作站上复制了这个问题。

In a team project I'm working on, setting a breakpoint in a file (say IdeasController.cs) will lead to erratic debugger behaviour if there's another file with the same name in the solution. I've reproduced the problem on several developers' workstations.

我在我们的Web API中的IdeasController.cs


另一个名为 IdeasController.cs 存在于我们单独的MVC 4 Web项目中。在下面的截图中,调试器显示了 Api-> IdeasController 源代码,但行亮点与 Web-> IdeasController的代码结构匹配。断点是重复的,其中一个在评论块的中间。

Another file called IdeasController.cs exists in our separate MVC 4 web project. In the screenshot below, the debugger shows the Api->IdeasController source code, but the line highlight matches the code structure of Web->IdeasController. The breakpoint is duplicated, with one of them in the middle of a comment block.


断点窗口显示断点同时两个文件:

The Breakpoint window shows the breakpoint in both files simultaneously:


在某些工作站上,调试器会遍历正确的行(不管行高亮);在其他人上,它高兴地步入无关的行(包括评论和空格)。我想这取决于它选择显示哪个源文件。

On some workstations the debugger steps through the correct lines (regardless of the line highlight); on others it cheerfully steps through irrelevant lines (including comments and whitespace). I'm guessing this depends on which source file it chooses to display.

我拖网了。当调试文件( *。pdb ),源文件和编译代码之间出现不匹配时,似乎出现了这种问题。有很多可能的原因:重复的文件名(这可能会混淆调试器 [5] ),过时的项目构建文件,无效的解决方案缓存或错误的构建配置。

I've trawled the Internet. This kind of problem seems to occur when there's a mismatch between the debug file (*.pdb), the source file, and the compiled code. There are a lot of possible causes: duplicate file names (which can confuse the debugger[5]), outdated project build files, invalid solution cache, or incorrect build configuration.

这些是我发现和尝试的解决方案:

These are the solutions I've found and tried:


  • 检查了我的构建配置。

  • Checked my build configuration.

  1. 确保项目不是内置在发布模式。

  2. 确保我们不要启用代码优化

  3. 确保项目的调试模块已正确加载。 (开始调试项目并检查调试> Windows > 模块。两个程序集都列出,未优化,符号状态为符号加载。)

  1. Made sure the project isn't built in release mode.
  2. Made sure we don't have code optimization enabled.
  3. Made sure the project's debug module was loaded correctly. (Started debugging the project and checked Debug > Windows > Modules. Both assemblies are listed, not optimized, and have a symbol status of "Symbols loaded".)


  • 重置调试元数据; Visual Studio缓存。

  • Reset the debugging metadata & Visual Studio cache.


    1. 关闭Visual Studio并删除解决方案缓存文件( *。suo < a href =http://www.dotnetmonster.com/Uwe/Forum.aspx/vs-net-debugging/2997/breakpoint-was-set-to-the-same-file-name-in-different = noreferrer> [1]

    2. 删除每个项目的构建输出( bin obj 文件夹)。 (为了将来参考:在Windows资源管理器中打开解决方案文件夹,并在搜索框中输入: type:folder AND(name = = OR = name = = obj)

    3. 删除程序集缓存文件夹( C:\Documents and Settings\< user> \Local Settings\Application Data\dl3 )。 [2 ] [3 ]

    1. Closed Visual Studio and deleted the solution cache file (*.suo).[1]
    2. Deleted each project's build output (the bin and obj folders). (For future reference: open the solution folder in Windows Explorer and type this in the search box: "type:folder AND (name:=bin OR name:=obj)".
    3. Deleted the assembly cache folder (C:\Documents and Settings\<user>\Local Settings\Application Data\dl3).[2][3]


  • 这些都没有任何效果我可以重命名其中一个文件(不重命名该类)来临时解决问题,但这远不是理想的。

    None of these had any effect. I can rename one of the files (without renaming the class) to temporarily work around the problem, but that's far from ideal.

    第14页我的最新Google搜索,建议将不胜感激。)

    Page 14 of my latest Google search. Suggestions would be much appreciated. :)

    推荐答案

    我刚刚遇到了同样的问题。删除了包含受影响的项目/源文件的解决方案的.suo文件。

    I just had the exact same problem. What solved it for me was deleting the .suo files belonging to the solution that contained the affected project/source file.

    我也删除了我的本地符号缓存,但是我没有认为这与它有任何关系。

    I also deleted my local symbolcache but I don't think that had anything to do with it.

    (我的解决方案包含多个项目,一个项目中的一个文件(DataAdapter.cs)受到此影响(VisualStudio放入我的断点在pdb属于System.Data.DataAdapter),我直接打开了.csproj文件,并能够正确设置断点。)

    (My solution contains multiple projects, one file (DataAdapter.cs) in one project was affected by this (VisualStudio put my breakpoints in the pdb belonging to System.Data.DataAdapter). I opened the .csproj file directly and was able to correctly set the breakpoint.)

    这篇关于如果多个文件具有相同的名称,则Visual Studio断点会在错误的源文件(或多个文件)中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆