title: Visual Studio breakpoints break in the wrong source file (or multiple files simultaneously) if multiple files have the same name
body: <p>In a team project I'm working on, setting a breakpoint in a file (say <code>IdeasController.cs</code>) 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.</p>
  
  <h3>Example</h3>
  
  <p>I set a breakpoint in <code>IdeasController.cs</code> in our Web API:</p>
  
  <blockquote>
    <p><img src="https://i.imgur.com/WDd8r.png" alt="Breakpoint set in code"></p>
  </blockquote>
  
  <p>Another file called <code>IdeasController.cs</code> exists in our separate MVC 4 web project. In the screenshot below, the debugger shows the <code>Api-&gt;IdeasController</code> source code, but the line highlight matches the code structure of <code>Web-&gt;IdeasController</code>. The breakpoint is duplicated, with one of them in the middle of a comment block.</p>
  
  <blockquote>
    <p><img src="https://i.imgur.com/SFkat.png" alt="Debugger highlight does not match code structure"></p>
  </blockquote>
  
  <p>The Breakpoint window shows the breakpoint in both files simultaneously:</p>
  
  <blockquote>
    <p><img src="https://i.imgur.com/spDTx.png" alt="Breakpoint spans both files"></p>
  </blockquote>
  
  <p>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.</p>
  
  <h3>What I've tried</h3>
  
  <p>I've trawled the Internet. This kind of problem seems to occur when there's a mismatch between the debug file (<code>*.pdb</code>), the source file, and the compiled code. There are a lot of possible causes: duplicate file names (which can confuse the debugger<sup><a href="http://www.velocityreviews.com/forums/t72561-asp-net-debugger-shows-wrong-line.html" rel="noreferrer">[5]</a></sup>), outdated project build files, invalid solution cache, or incorrect build configuration.</p>
  
  <p>These are the solutions I've found and tried:</p>
  
  <ul>
  <li>Checked my build configuration.
  
  <ol>
  <li>Made sure the project isn't built in release mode.</li>
  <li>Made sure we <a href="http://joelblogs.co.uk/2010/02/10/visual-studio-2008-%E2%80%93-when-debugging-highlights-the-wrong-line/" rel="noreferrer">don't have code optimization enabled</a>.</li>
  <li>Made sure the project's debug module was loaded correctly. (Started debugging the project and checked <code>Debug</code> > <code>Windows</code> > <code>Modules</code>. Both assemblies are listed, not optimized, and have a symbol status of "Symbols loaded".)</li>
  </ol></li>
  <li>Reset the debugging metadata &amp; Visual Studio cache.
  
  <ol>
  <li>Closed Visual Studio and deleted the solution cache file (<code>*.suo</code>).<sup><a href="http://www.dotnetmonster.com/Uwe/Forum.aspx/vs-net-debugging/2997/breakpoint-was-set-to-the-same-file-name-in-different" rel="noreferrer">[1]</a></sup></li>
  <li>Deleted each project's build output (the <code>bin</code> and <code>obj</code> folders). (For future reference: open the solution folder in Windows Explorer and type this in the search box: "<code>type:folder AND (name:=bin OR name:=obj)</code>".</li>
  <li>Deleted the assembly cache folder (<code>C:\Documents and Settings\&lt;user&gt;\Local Settings\Application Data\dl3</code>).<sup><a href="http://minkmachine.reine.se/2006/04/breakpoint-issues-in-visual-studio-net/" rel="noreferrer">[2]</a><a href="http://weblogs.asp.net/psheriff/archive/2011/11/08/clean-up-after-visual-studio.aspx" rel="noreferrer">[3]</a></sup></li>
  </ol></li>
  </ul>
  
  <p>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.</p>
  
  <h3>Where I am now</h3>
  
  <p>Page 14 of my latest Google search. Suggestions would be much appreciated. :)</p>