C# 向ShellLibrary添加路径时出现COMException

C# 向ShellLibrary添加路径时出现COMException,c#,windows-api-code-pack,C#,Windows Api Code Pack,我正在使用Windows7覆盖一个现有的库并向其中添加新的路径,使用可通过的托管包装器 有时,我似乎无法以任何方式再现这一点,在向库添加路径时会抛出COMException: System.Runtime.InteropServices.COMException (0x80070497): Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497) at Microsoft.WindowsAP

我正在使用Windows7覆盖一个现有的库并向其中添加新的路径,使用可通过的托管包装器

有时,我似乎无法以任何方式再现这一点,在向库添加路径时会抛出
COMException

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)
代码非常简单。在
Add
方法上抛出错误

using ( var activityContext = new ShellLibrary( LibraryName, true ) )
{
    Array.ForEach( dataPaths, p => activityContext.Add( p.LocalPath ) );
}
是否存在我可以复制/测试的预期此异常的特定场景?


假设这是shell库中的一个bug,我可以捕获异常并重试几次操作,尽管我希望有一个更干净的“解决方案”。

基于异常,我假设您遇到了某种权限问题。基于5分钟的研究,如果API本身有缺陷,我会捕获并记录异常,但如果很少发生,我不会对此采取任何措施。