C# 在Windows 8.1 AppStore应用程序中写入/读取文件
我有一个Windows 8.1应用程序,我想从中写入和读取应用程序包中“资产”文件夹中的XML文件 我在C# 在Windows 8.1 AppStore应用程序中写入/读取文件,c#,async-await,windows-applications,C#,Async Await,Windows Applications,我有一个Windows 8.1应用程序,我想从中写入和读取应用程序包中“资产”文件夹中的XML文件 我在this.InitializeComponent()之后从页面构造函数调用以下方法行: private async void ReadXML() { var uri = new System.Uri("ms-appdata:///Assets/gameInfo.xml"); StorageFile file = await Windows.Storage
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:
用户代码未处理System.ArgumentException
HResult=-2147024809
消息=值不在预期范围内。
Source=mscorlib
堆栈跟踪:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在lightsoutap.Random4x4.d__0.MoveNext()处
内部异常:
有人知道为什么会抛出此异常吗?谢谢您的帮助。我尝试用ms app代替ms appdata,它修复了这个错误。感谢您的帮助。请提供完整的异常详细信息。单击按钮,然后将信息编辑为您的问题。我这样做了。谢谢你给我看这个把戏!!你在哪里发现这个异常?不,这是被抛出的,我不知道为什么。