C# uwp mostrecentlyusedlist添加导致COM类型异常

C# uwp mostrecentlyusedlist添加导致COM类型异常,c#,xaml,uwp,comexception,storagefile,C#,Xaml,Uwp,Comexception,Storagefile,StackTrace internal async static Task AddToHistory(StorageFile fileToBeAdded) => await DispatcherHelper.ExecuteOnUIThreadAsync(() => StorageApplicationPermissions.MostRecentlyUsedList.Add(fileToBeAdded, "", RecentStorageItemVisibility.AppAndSys

StackTrace

internal async static Task AddToHistory(StorageFile fileToBeAdded) => await DispatcherHelper.ExecuteOnUIThreadAsync(() => StorageApplicationPermissions.MostRecentlyUsedList.Add(fileToBeAdded, "", RecentStorageItemVisibility.AppAndSystem));
“在Windows.Storage.AccessCache.StorageItemMostTrecentlyUsedList.Add(IStorageItem文件、字符串元数据、RecentStorageItemVisibility)\r\n在FluentVideoPlayer.Helpers.FileHelper.c\u DisplayClass7\u 0.b\u 0()\r\n在Microsoft.Toolkit.Uwp.Helpers.DispatcherHelper.c\u DisplayClass10\u 0`1.b\u 0()”

我正在尝试将一个存储文件添加到最常用的列表中,因此我遇到了此异常

例外情况

对COM组件的调用返回了HRESULT E_FAIL

代码

internal async static Task AddToHistory(StorageFile fileToBeAdded) => await DispatcherHelper.ExecuteOnUIThreadAsync(() => StorageApplicationPermissions.MostRecentlyUsedList.Add(fileToBeAdded, "", RecentStorageItemVisibility.AppAndSystem));
我在静态类中使用这个静态方法,因此我可以从应用程序中的任何页面调用它。我可以验证StorageFile对象是否为null和完美。正如您在代码中看到的,我还尝试使用DispatcherHelper来解决它,但无论是否使用它,这两种情况都会发生异常

更新

internal async static Task AddToHistory(StorageFile fileToBeAdded) => await DispatcherHelper.ExecuteOnUIThreadAsync(() => StorageApplicationPermissions.MostRecentlyUsedList.Add(fileToBeAdded, "", RecentStorageItemVisibility.AppAndSystem));
我也尝试添加到FutureAccessList,而不是最常用的列表,在这两种情况下我都会遇到相同的错误

更新2

访问列表通常不会导致任何错误,就像我可以使用以下代码访问它一样

var mlist = StorageApplicationPermissions.MostRecentlyUsedList;
var entries = mlist.Entries;

仅当我尝试向其中添加存储文件时,才会发生错误。

问题在于部分存储文件,我实际上是根据以下博文从KnownFolders.VideoLibrary查询文件的

所以,当我们使用下面的索引选项时,它实际上为我们初始化了部分存储文件,当我们试图将其添加到最近使用的列表或FutureAccessList时,会导致异常

IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties
因此,为了解决这个问题,我现在使用了索引器选项。在可用时使用Indexer现在我没有得到任何异常,但当然我牺牲了以前使用部分存储文件的速度。这是令人失望的,因为当尝试使用完整的storagefile执行作业时,它应该根据博客文章自动将部分storagefile初始化为完整的storagefile。但不幸的是,情况并非如此


谢谢你今天的报道。您是对的-Windows在内部处理部分存储文件时存在错误。目前的另一个解决方法是使用:StorageFile.GetFileFromPathAsync(fileToBeAdded.Path)为要添加到MRU或FAL的文件创建新的StorageFile对象。您仍然可以使用快速枚举,但将文件添加到MRU时会减慢速度