[英]Writing/Reading To/From File Windows 8.1 AppStore App
我有一个Windows 8.1应用程序,我要从其中写入和读取XML文件,该文件位于应用程序包的“资产”文件夹中。
我在this.InitializeComponent();
之后从页面构造函数调用以下方法this.InitializeComponent();
线:
private async void ReadXML()
{
var uri = new System.Uri("ms-appdata:///Assets/gameInfo.xml");
StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
XmlDocument reader = new XmlDocument();
reader.LoadXml(file.ToString());
XmlNodeList nodes = reader.DocumentElement.ChildNodes;
string attr = nodes[0].Attributes[0].InnerText;
int bestTime;
if (attr != null && int.TryParse(attr, out bestTime))
BestTime = bestTime;
}
当我导航到包含此代码的页面并运行时,我在StorageFile file...
行上抛出ArgumentException。 这是异常详细信息:
System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=Value does not fall within the expected range.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at LightsOutApp.Random4x4.<ReadXML>d__0.MoveNext()
InnerException:
有谁知道为什么会引发此异常? 感谢您的任何帮助。
我尝试执行ms-app而不是ms-appdata,它修复了该错误。 谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.