2015-06-13 32 views
0

我有一個Windows 8.1應用程序,我想從中寫入並讀取放置在應用程序包中的「Assets」文件夾中的XML文件。寫入/讀取/從文件Windows 8.1 AppStore App

我打電話從頁面構造函數中的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: 

有沒有人有任何想法爲什麼這個異常被拋出?感謝您的任何幫助。

+2

請提供完整的例外詳情。單擊[複製異常詳細信息](http://blogs.msdn.com/b/saraford/archive/2008/08/07/did-you-know-you-can-copy-the-exception-details-with-一鍵從異常助手-276.aspx)按鈕,然後將這些信息編輯爲您的問題。 –

+0

我做到了。謝謝你給我看這招! –

+0

你在哪裏捕捉這個異常? –

回答

0

我試着做ms-app而不是ms-appdata,它修正了那個錯誤。感謝您的幫助。