I have some data in my Windows 8 application that should be sent using and only some static data. Actually: this is a simple XML file that needs to be deserialized.
Data is saved in Assets \ data.xml (Assets is the default folder from the Blank App template).
I use this piece of code to access it:
private static async Task<MyObject> Load() { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { return new SampleData(); } var uri = new Uri("ms-appx:///Assets/data.xml"); Debug.WriteLine("Getting file from Application"); var file = await StorageFile.GetFileFromApplicationUriAsync(uri); Debug.WriteLine("Opening file for reading async"); var stream = await file.OpenStreamForReadAsync(); var serializer = new XmlSerializer(typeof(MyObject)); Debug.WriteLine("Begin deserialization"); var result = (MyObject)serializer.Deserialize(stream.AsInputStream().AsStreamForRead()); return result; }
Call Method:
public static MyObject GetMyObject() { if (_myObject == null) { _myObject = Load().Result; } return _myObject; }
The "funny" part about this:
If I set a breakpoint in var uri = new Uri(...); and I use F11 to go through the code, everything works as expected. I get all the debugging lines, and my application shows static data as needed.
If I donβt set a breakpoint and go to this piece of code, I get only the output of Debug Getting a file from Application and nothing else happens. It seems that GetFileFromApplicationUriAsync() never returns. I waited more than five minutes, but nothing happened.
Does anyone have an idea?
source share