1

我尝试使用文件路径(只是一个字符串)作为 ApplicationDataContainer 中的键,但它失败了。有3个不同的问题:

  1. 如果密钥是文件路径,即使密钥不存在,容器也会报告密钥存在
  2. 如果您尝试添加一个确实存在的文件路径的键,它不会做任何事情。
  3. 如果您尝试添加一个不存在的文件路径的键,则会引发异常:

有没有人见过这样的问题,这是预期的行为吗?我找不到任何说明文件路径作为密钥无效的文档,对于我来说,MS 试图采用他们所知道的随机字符串并将其视为文件路径,这对我来说似乎很奇怪。

 An unhandled exception of type 'System.Exception' occurred in mscorlib.dll

 WinRT information: Error trying to query the application data container item info

 Additional information: The specified path is invalid.

示例代码:

var container = ApplicationData.Current.LocalSettings.CreateContainer("SomeContainerName", ApplicationDataCreateDisposition.Always);
if (container.Values.ContainsKey("C:\\Some_Fake_Path") == false) // This will report as true even though the key is not in the container
      {
        //If you try to run this line it throws an exception that file can not be found even though it is just a key value pair
        container.Values.Add("C:\\Some_Fake_Path", "SomeStuffHere");

        //This line won't throw, but it won't actually add a key/value pair either
        container.Values.Add("C:\\This_Path_Actually_Exists\\SomeFile.txt", "SomeStuffHere");
      }
4

0 回答 0