GetFileFromPathAsync 给出 "The parameter is incorrect" 异常

GetFileFromPathAsync giving "The parameter is incorrect" exception

我已经开始接触 Windows 通用平台编程(Windows 10、VS2015、c#)并遇到一些基本问题..

我在 MusicLibrary 中有一个子文件夹,其中有一个文件 test.txt。目前,我强制 GetFileFromPathAsync 为非异步(我正处于将旧应用程序转换为新目标的早期阶段,因此稍后会出现异步)。根据一些示例,以下代码应该可以工作

            string parentPath = returnStorage(_location).Path;
            string filePath = Path.Combine(parentPath, _filename);
            StorageFile _file = StorageFile.GetFileFromPathAsync(filePath).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();

但我遇到了异常"The parameter is incorrect",但我不明白为什么

_filename = "ggmptest_04a\test.txt"
parentPath = ""
_location is musicLibrary

在我的代码的其他地方,我可以为 musicLibrary 创建子文件夹和文件,并使用 GetItemsAsync 列出那里的文件。但是这个 GetFileFromPathAsync 调用使我失败了。

拜托,什么是其他人都能立即看到但现在却避开我的眼睛的显而易见的东西。?

如果提供的路径不是绝对路径,

GetFileFromPathAsync 将抛出 ArgumentException

在您的情况下,filePath 似乎包含一个相对路径,因为 parentPath 是一个空字符串,将其与 _filename 组合将产生一个相对路径。