title: VS2013 runs old code; clean + rebuild doesn't suffice; after deleting bin + obj folders, the first rebuild fails, but 2nd succeeds
body: <h1>Original post</h1>
  
  <p>I am building an ASP.NET application with Visual Studio 2013 Premium for the .NET framework version 4.5, using IIS Express in the debugging process. Now I have run into a problem that happened with other projects before (very very rarely), but is extremely frequently occurring in this one:</p>
  
  <p>Changes in my code often are not compiled correctly and thus an older version of the program is started in IIS. I first noticed this when I got a <code>NullReferenceException</code> in one line of code, then added a check for <code>null</code> around it and then got the same error again, just now in the line where the check happened (which is the line number where the exception occurred before). Another symptom is that no breakpoints are hit anymore because of missing symbols (due to the discrepancy in the version of the code I think).</p>
  
  <p>Now I have read all kinds of threads here and on MSDN regarding this issue, and it seems like many people have this from time to time and noone has a solution that works for everyone.</p>
  
  <p>Doing a clean/rebuild does not work at all when I encounter this problem, but usually deleting the bin <strong>and obj</strong> folders did the trick. But what happens now is the following:</p>
  
  <p>After starting the debugging process (<code>F5</code>), I can see that my breakpoints aren't hit, so I stop it, delete the bin/obj folders and <em>Rebuild All</em>. This does <em>not</em> work and always fails with many errors saying that a namespace could not be found (even though IntelliSense proposes it there and it does in fact exist) and the assembly (which would provide the namespace) was missing (and it indeed is in the final output folder of the startup project; but it got created in its own project bin folder...). Then I <em>Rebuild All</em> a second time and it will magically work. The next start of the program does everything as I wish it to be. But after that, I am at the point where already the 2nd or 3rd restart produces the problem again (no breakpoints, old code) and I can start over with deleting the folders. I have to add that this behaviour started last week and got ever more frequent since. It wasn't always at the point where I had to delete the folders after every 2nd try.</p>
  
  <p>All this is of course unbearable as it's impossible to work under these circumstances. But I am at a loss as to what to do. I have worked (among others) through <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/23e70e79-970d-423f-b434-12681b88ef2c/visual-studio-2012-debug-runs-old-code" rel="nofollow noreferrer">this MSDN thread</a> and <a href="https://stackoverflow.com/questions/2301216/the-breakpoint-will-not-currently-be-hit-no-symbols-have-been-loaded-for-this-d?rq=1">this SO question</a>, but nothing seems to work for me.</p>
  
  <p>Do you have any other suggestions? Could there be something wrong at some point that produces this kind of behavior explicitly? Especially the part where the first rebuild doesn't but the 2nd does indeed work puzzles me and feels like there could be something I'm doing wrong.</p>
  
  <p><strong>Edit:</strong> I tested another scenario right now: After the first rebuild I get the above errors about the missing assembly. Then I <em>really</em> remove the reference to that assembly and despite that, the 2nd rebuild still goes through without errors now! How can that be?</p>
  
  <p><strong>Edit2:</strong> So as a summary, every 2nd time I try to run the program with a breakpoint I wish to hit, symbols won't be loaded and I have to delete the bin/obj folders. Then I have to rebuild <em>twice</em>, after the 2nd time it works, starts and hits breakpoints. But the next time after this, it won't hit breakpoints anymore (even if I don't change anything in the code itself!) and I have to start over.</p>
  
  <h1>Update</h1>
  
  <p>I now tried starting VS as admin and double-checked that the references were project references. After just batch cleaning the whole solution, it would start up but then show me the missing assembly exception for the <code>DataAccess</code> project in IE. I then deleted the bin/obj folders and rebuilt the project once. Now I'm getting (as usual) the following errors:</p>
  
  <blockquote>
    <p>The type or namespace 'Business' does not exist in the namespace 'MyNamespace' (are you missing an assembly reference?)</p>
    
    <p>Could not resolve this reference. Could not locate the assembly "Business, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.</p>
  </blockquote>
  
  <p>The thing is, the assembly <code>Business.dll</code> lies in the <code>MySolution\Business\bin\Debug</code> folder as well as in the final <code>MySolution\Frontend\bin</code> folder, and it is definitely the version that I just built. So why does the compiler complain? It feels like there's something wrong with the build order, but that shouldn't be the case if I purely use project references, should it?</p>
  
  <p>Now, again as usual, the 2nd rebuild works fine, and I can hit my breakpoints once after that. Then I added a trivial line <code>int i = 0;</code> in the code right after the breakpoint and restarted the program, and again it tells me the breakpoint won't be hit and that symbols aren't loaded. I then checked <em>Debug -> Windows -> Modules</em> to see</p>
  
  <blockquote>
    <p>Cannot find or open the PDB file.</p>
  </blockquote>
  
  <p>for the <code>Business</code> and <code>DataAccess</code> projects while yesterday I got</p>
  
  <blockquote>
    <p>PDB does not match image.</p>
  </blockquote>
  
  <p>for those.</p>
  
  <p>But when right clicking the <code>Business</code> project in <em>Modules</em> and selecting <em>Load symbols</em>, it immediately prompts me to the <code>obj\Debug</code> folder of the<code>project where a</code>*.pdb` file resides that has been created on build (confirmed via the timestamp). Choosing this file yields</p>
  
  <blockquote>
    <p>A matching symbol file was not found in this folder.</p>
  </blockquote>
  
  <p>But I just clicked that file, so there must be something wrong with the 'matching' part, right? Do you have any further ideas, as I'm totally out of knowledge here?</p>
  
  <h1>Update 2</h1>
  
  <p>After updating Visual Studio 2013 to Update 3 I get an additional compiler warning when doing the first <em>Rebuild All</em> after deleting the bin/obj folders:</p>
  
  <blockquote>
    <p>The type 'MyNamespace.Business.Providers.BusinessProvider' exists in both 'MySolutionPath\StartupProject\bin\Business.dll' and 'MySolutionPath\Business\bin\Debug\Business.dll'.</p>
  </blockquote>
  
  <p>I wonder if/why this is an issue, as it is VS itself that must have copied the <code>Business.dll</code> to the StartupProject's bin folder. Could that maybe point to anything worth looking at?</p>