How to save Class Object in ApplicationData in metro style app RRS feed

  • Question

  • Hi All,

    I want to share a class object between background task and my mobile broadband Metros app.

    As ApplicationData.Current.LocalSettings does not solve the purpose as it do not support the objects.

    Please suggest that how I can save a class object in ApplicationData or some other way to do it. 



    Saturday, June 30, 2012 12:56 PM

All replies

  • Hello there,

    Sounds like you need to serialize the complex object to work with ApplicationData by adding [DataContract] attributes etc

    Heres a good thread that should help


    Sunday, July 1, 2012 4:56 PM
  • and when serializing beware of the limitations of localsettings (storage limit). make sure there is enough space in localsettings, else use localfiles
    Sunday, July 1, 2012 5:48 PM
  • HI bluemountain43

    I also followed the same link.

    But I am able to save the class object to application local folder successfully even I have verified that file exist at application local folder.

    But when I tried to get it from the application folder I got error "Access denied".

    My sample code is pasted below:


    static private Dictionary<string, object> parsedResponseData = new Dictionary<string, object>();       

     public async void GetPlanFromApplicationData()
                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(resourceLoader.GetString("ParsedDataFile"));
                if (file == null)

                IRandomAccessStream inputStream = await file.OpenReadAsync();
                DataContractSerializer dataSerializer = new DataContractSerializer(typeof(Dictionary<string, object>), new Type[] { typeof(GetPlanResponse) });
                parsedResponseData = (Dictionary<string, object>)dataSerializer.ReadObject(inputStream.AsStreamForRead());

                GetPlanResponse planData = parsedResponseData["planDetails"] as GetPlanResponse;
                GetPlansData(this, planData);

    IRandomAccessStream inputStream = await file.OpenReadAsync(); I am getting error at this line.

    Please suggest what I am missing here.



    Monday, July 2, 2012 7:48 PM
  • access denied means the file is already opened somewhere else in your application. make sure you close the stream
    • Proposed as answer by Dave SmitsMVP Sunday, July 8, 2012 5:46 PM
    Sunday, July 8, 2012 5:46 PM
  • Hi Dave

    I  want to access that same object from the Background task Run() method then how to do it please help me.


    Thursday, February 14, 2013 3:23 PM