【发布时间】:2018-09-22 14:54:48
【问题描述】:
堆栈跟踪
" 在 Windows.Storage.AccessCache.StorageItemMostRecentlyUsedList.Add(IStorageItem 文件、字符串元数据、RecentStorageItemVisibility 可见性)\r\n 在 FluentVideoPlayer.Helpers.FileHelper.c__DisplayClass7_0.b__0()\r\n 在 Microsoft.Toolkit .Uwp.Helpers.DispatcherHelper.c__DisplayClass10_0`1.b__0()"
我正在尝试将 StorageFile 添加到 MostRecentlyUsedList,结果出现此异常。
例外
HRESULT E_FAIL 已从对 COM 组件的调用中返回
代码
internal async static Task AddToHistory(StorageFile fileToBeAdded) => await DispatcherHelper.ExecuteOnUIThreadAsync(() => StorageApplicationPermissions.MostRecentlyUsedList.Add(fileToBeAdded, "", RecentStorageItemVisibility.AppAndSystem));
我有这个静态方法可以在静态类中使用,所以我可以从应用程序中的任何页面调用它。我可以验证 StorageFile 对象不为空且完美我还尝试使用 DispatcherHelper 来解决它,正如您在代码中看到的那样,但是无论有没有它,两种情况都会发生异常。
更新
我也尝试添加到 FutureAccessList 而不是 MostRecentlyUsedList 并且在这两种情况下我都遇到相同的错误
更新 2
正常访问列表不会导致任何错误,就像我可以使用以下代码访问它一样
var mlist = StorageApplicationPermissions.MostRecentlyUsedList;
var entries = mlist.Entries;
只有在我尝试向其中添加存储文件时才会出现错误。
【问题讨论】:
标签: c# xaml uwp comexception storagefile