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.
I set a breakpoint in IdeasController.cs
in our Web API:
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.
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:
Debug
> Windows
> Modules
. Both assemblies are listed, not optimized, and have a symbol status of "Symbols loaded".)*.suo
).[1]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)
".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.
Page 14 of my latest Google search. Suggestions would be much appreciated. :)
If no better alternatives exist, you could put the breakpoint in code:
System.Diagnostics.Debugger.Break();
Just don't forget to remove it afterwards...