I have some data in my windows 8 application which should be shipped with and is just some static data. In fact: It's a simple xml file which should get deserialized.
The data is saved in Assets\data.xml (Assets is the default folder from the Blank App Template).
I'm using 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;
}
Calling method:
public static MyObject GetMyObject()
{
if (_myObject == null)
{
_myObject = Load().Result;
}
return _myObject;
}
The "funny" part about that is:
If I set a breakpoint at var uri = new Uri(...);
and use F11 to step through the code, everything works as expected. I get all of the debug lines and my Application shows the static data as wanted.
If I don't set a breakpoint and don't step over this piece of code, I only get the Debug output of Getting a file from Application
and nothing more happens. It seems that GetFileFromApplicationUriAsync()
never comes back. I waited more than five minutes but still nothing happend.
Anyone got any idea?