title: Visual Studio 2008 project file does not load because of an unexpected encoding change
body: <p>In our team we have a database project in visual Studio 2008 which is under source control by Team Foundation Server. Every two weeks or so, after one co-worker checks in, the project file won't load on the other developers machines. The error message is:</p>
  
  <blockquote>
    <p>The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.</p>
  </blockquote>
  
  <p>When I look at the project file in Notepad++, the file looks like this:</p>
  
  <p><code>��&lt;NUL?NULxNULmNULlNUL NULvNULeNULrNULsNULiNULoNULnNUL</code> ...</p>
  
  <p>and so on (you can see <code>&lt;?xml version</code> in this)
  whereas an normal project file looks like:</p>
  
  <p><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;</code>  ...</p>
  
  <p>So probably something is wrong with the encoding of the file. This is a problem for us because it turns out to be impossible to get the file encoding correct again. The 'solution' is to throw away the project file an get the last know working version from source control.</p>
  
  <p>According to the file, the encoding should be UTF-16. According to Notepad++, the corrupted file is actually UTF-8.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Why is Visual Studio messing up the encoding of the
  project file,
  apparently at random times and at
  random machines?</li>
  <li>What should we do to prevent this?</li>
  <li>When it has happened, is there a
  possibility to restore the current
  file in the correct encoding instead
  of pulling an older version from
  source control?</li>
  </ul>
  
  <p>As a last note: the problem is with one single project file, all other project files don't expose this problem.</p>
  
  <p>UPDATE: Thanks to Jon Skeet's suggestion I have the answer to question number three.
  When I replace the first nine bytes EF BB BF EF BF BD EF BF BD by the two bytes FF FE, the project file will load again.</p>
  
  <p>This leaves still the question why Visual Studio corrupts the file.</p>