0
votes

I am building a Windows Phone 8.1 RT App which runs MP3 files in Background task.

I followed the steps in the sample code shown here : http://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319

In MyPlaylistManager Project I would like to build my own Playlist from XML file.

When I try to access this XML file I am getting an exception.

An exception of type 'System.Xml.XmlException' occurred in SYSTEM.XML.NI.DLL but was not handled in user code

Additional information: An internal error has occurred.

I have added the XML file to the Project and set

Build Action : Content

Copy to Output Directory : Copy if newer

To access the file I tired below options :

  XDocument xdoc = XDocument.Load("ms-appx:///XYZ.xml");

  XDocument xdoc = XDocument.Load("XYZ.xml");

XDocument.Load is supported in Windows Phone 8.1 as per the documentation: http://msdn.microsoft.com/en-us/library/bb343181(v=vs.110).aspx

Directory Structure of my Solution

Any pointers on what I am doing wrong. Thanks.

1
Remember that I am trying to do this in a background taskSaqib Vaid
DOes it work when you deserialize it in the foreground process? Can you also check if the file exists and maybe its content - StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("XYZ.xml");?Romasz
I tried your code but to check if file exists : An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code. You r right, its not able to find the file.Saqib Vaid
@Romasz When I try GetFileAsync("ms-appx:///XYZ.xml"); I get An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code Additional information: Value does not fall within the expected range.Saqib Vaid

1 Answers

1
votes

I think that the problem is, because you aren't providing the correct path. Your file is in project MyPlaylistManager. Try to use:

XDocument xdoc = XDocument.Load("ms-appx:///MyPlaylistManager/Quran.xml");
// or like this:
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"MyPlaylistManager\Quran.xml");

Also not forget to include MyPlaylistManager in references. Maybe this answer will also help a little.

EDIT - you may also try to use XDocument.Load(Stream) - then in your BackgroundTask first get the StorageFile then load XDocument using Stream got from the file.