COMException while adding paths to a ShellLibrary

3

I'm using Windows 7's Shell Libraries to overwrite an existing library and add new paths to it, using the managed wrapper available through the Windows API Code Pack 1.1.

Every now and then, I can't seem to reproduce this in any way, a COMException is thrown while adding the paths to the library:

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)

The code is quite straightforward. The error is thrown on the Add method.

using ( var activityContext = new ShellLibrary( LibraryName, true ) )
{
    Array.ForEach( dataPaths, p => activityContext.Add( p.LocalPath ) );
}

Is there a certain scenario where this exception is to be expected which I can reproduce/test for?

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'.

c#
windows-api-code-pack
asked on Stack Overflow Aug 1, 2013 by Steven Jeuris • edited Aug 1, 2013 by Steven Jeuris

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0