C# 无法替换当前.LocalFolder中的现有文件

C# 无法替换当前.LocalFolder中的现有文件,c#,windows,windows-runtime,C#,Windows,Windows Runtime,我有一个图像文件,我从选择器得到。我将其另存为“me.png”: Windows.Storage.ApplicationData.Current.LocalFolder 如果我再次执行操作以尝试用新文件覆盖旧文件,应用程序将崩溃: An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code Additional i

我有一个图像文件,我从选择器得到。我将其另存为“me.png”:

Windows.Storage.ApplicationData.Current.LocalFolder
如果我再次执行操作以尝试用新文件覆盖旧文件,应用程序将崩溃:

    An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

If there is a handler for this exception, the program may be safely continued.
我用来覆盖文件的代码是:

            await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "me.png", Windows.Storage.NameCollisionOption.ReplaceExisting);
知道为什么会这样吗?它第二次在那行代码上崩溃了。如果我将“碰撞”选项更改为GenerateUniqueName,它将正常工作,因此覆盖该文件似乎有问题

更新:

完整代码

    localSettings.Values["me_image_path"] = "Asssets/pinkBackground.png";
                 tile.BackgroundImage = localSettings.Values["me_image_path"];

var picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file == null) return;
            await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "me.png", Windows.Storage.NameCollisionOption.ReplaceExisting);

            localSettings.Values["me_image_path"] = "ms-appdata:///local/me.png";
            tile.BackgroundImage = localSettings.Values["me_image_path"];

也许你还开着旧档案?我也是这么想的。我将它显示在GridViewItem上,因此在调用CopySync之前,我会将GridViewItem的图像更改为其他内容。您是真的覆盖了me.jpg还是这是一个系统文件?它是我从用户图片库获取的文件,并复制到我的本地存储文件夹。我试图覆盖我在本地保存的版本。@如果有帮助,我添加了完整的代码