访问LocalFolder会抛出UnauthorizedAccessException 80070005 [英] Accessing LocalFolder throws UnauthorizedAccessException 80070005

查看:74
本文介绍了访问LocalFolder会抛出UnauthorizedAccessException 80070005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,在我的应用中,我正在尝试访问ApplicationData.Current.LocalFolder,然后访问名为"UserSounds"的特定文件夹。由app创建。应用程序首次在设备上启动时会创建此文件夹。不确定在创建此文件夹时是否会抛出异常
,或者稍后当应用程序尝试访问此文件夹时,因为我只有来自DevCenter的崩溃报告而且从未在我的设备上发生过。

这是我的代码:

Hello, in my app I'm trying to access ApplicationData.Current.LocalFolder and then specific folder called "UserSounds" created by app. App creates this folder first time it is launched on the device. Not sure if the exception is being throwed when creating this folder or later when app tries to access this folder, as I have only crash reports from DevCenter and never happened on my devices.

Here is my code:

private static async Task<StorageFolder> GetUserSoundsFolderAsync()
        {
            if (_userSoundsFolder == null)
            {
                var userSoundsFolder = await LocalFolder.TryGetItemAsync(UserSoundsFolderRelPath);
                if (userSoundsFolder == null || !userSoundsFolder.IsOfType(StorageItemTypes.Folder))
                {
                    Debug.WriteLine("UserSoundsFolder not found, creating...");
                    userSoundsFolder = await LocalFolder.CreateFolderAsync(UserSoundsFolderRelPath, CreationCollisionOption.OpenIfExists);
                    Debug.WriteLine($"UserSoundsFolder created at: {userSoundsFolder.Path}");
                }

                _userSoundsFolder = (StorageFolder) userSoundsFolder;
            }
            return _userSoundsFolder;
        }

public const string UserSoundsFolderRelPath = "UserSounds";

private static StorageFolder _localFolder;
public static StorageFolder LocalFolder => _localFolder ?? (_localFolder = ApplicationData.Current.LocalFolder);

以下是DevCenter报告的截图:

Here are screenshots from DevCenter report:

推荐答案

嗨Viktor,

Hi Viktor,

虽然我可以不要告诉你究竟是什么导致了这些错误,但似乎有一种方法可以重现那次崩溃。如果文件夹已存在但由于某种原因无法访问,则可能发生UnauthorizedAccessException。  

Though I can't tell you exactly what is causing those errors, but it seems there is a way to reproduce that crash. UnauthorizedAccessException can occur in case the folder already exists but it's not accessible for some reason.  

如何重现它;


  1. 在资源管理器中打开应用程序的LocalState文件夹并将UserSounds转为隐藏文件夹。
  2. 然后在Visual Studio中运行应用程序。

HP15上可能会发生类似情况笔记本电脑在故障日志中困扰着。尝试进一步调查文件夹无法访问的条件。

Maybe something similar is happening on the HP15 Notebook PC haunting in the failure log. Try investigating further in what condition the folder can become inaccessible.


这篇关于访问LocalFolder会抛出UnauthorizedAccessException 80070005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆