title: COMException while adding paths to a ShellLibrary
body: <p>I'm using Windows 7's <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd797952%28v=vs.85%29.aspx" rel="nofollow">Shell Libraries</a> to overwrite an existing library and add new paths to it, using the managed wrapper available through the <a href="http://archive.msdn.microsoft.com/WindowsAPICodePack" rel="nofollow">Windows API Code Pack 1.1</a>.</p>
  
  <p>Every now and then, I can't seem to reproduce this in any way, a <code>COMException</code> is thrown while adding the paths to the library:</p>
  
  <pre><code>System.Runtime.InteropServices.COMException (0x80070497): Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497)
     at Microsoft.WindowsAPICodePack.Shell.IShellLibrary.Commit()
     at ... (local code from here on out)
  </code></pre>
  
  <p>The code is quite straightforward. The error is thrown on the <code>Add</code> method.</p>
  
  <pre><code>using ( var activityContext = new ShellLibrary( LibraryName, true ) )
  {
      Array.ForEach( dataPaths, p =&gt; activityContext.Add( p.LocalPath ) );
  }
  </code></pre>
  
  <p><strong>Is there a certain scenario where this exception is to be expected which I can reproduce/test for?</strong></p>
  
  <p>Assuming this is a bug in the shell libraries, I could just catch the exception and retry doing the operation a couple of times, although I'm hoping for a cleaner 'solution'.</p>