title: What is causing intermittent "Object reference not set to an instance of an object" at compile time in VS 2010?
body: <p>I am sorry if this is not really a coding question (it depends on if its my code causing the problem I suppose).</p>
  
  <p>I have seen this question: <a href="https://stackoverflow.com/questions/209465">Tracking down intermittent &#39;Object reference not set to an instance of an object.&#39; error on build</a></p>
  
  <p>However, it has not been of much help (although if you read the comments, you will see that I thought it did help for a while there).</p>
  
  <p>When I try publish my website, occasionally, I will get an error with no file or line reference:</p>
  
  <pre><code>Pre-compiling Web Site
  
  Building directory '/App_Code/'.
  Building directory '/'.: Publication (web): Object reference not set to an instance of an object.
  
  Pre-compilation Complete
  ------ Skipped Publish: Project X:\, Configuration: Debug Any CPU ------
  </code></pre>
  
  <p>I know the usual causes of "Object reference not set to an instance of an object" but this seems a bit different, isn't it supposed to be a runtime error? Not a build error? </p>
  
  <p>What is weird is that it happens, seemingly at random (about 25%-33% of the time). I can try to publish it and have it fail. Then try again straight after, without changing anything and it works fine.</p>
  
  <p>I started getting this error after moving some of my functions (VB.net btw) to a new file in the App_Code folder so they can be accessed by all pages of the site. </p>
  
  <p>If you need any more info, please let me know.</p>
  
  <p>Thanks,</p>
  
  <p>EDIT: After further investigation, it seems to only happen if I try to publish the website within a few seconds of saving changes to any file within it. What could cause this?</p>