locked
Windows Store app Serialize DataContract

    Question

  • Hello,

    I am writing a Windows Store App using C#. However got SuspensionManager failed when passing a DataContract object to Navigate.

    Here is the detail:

    1. Have a class:

        [DataContract]

         public class MyClass

        {

            [DataMember]

            public string Id {get; set;}

         }

    2. MainPage.xaml.cs

        MainPage contains a list of "MyClass"es, when one is selected, I call:

        this.Frame.Navigate(typeof(AnotherPage), selected_MyClass);

    3. Now I am on AnotherPage, but when I close the app by hitting Fn+Alt+F4, the SuspensionManager.SaveAsync() in App.xaml.cs throws an exception: SuspensionManager failed.

    The reason is in 2 that I passed an object of MyClass to AnotherPage.

    How to make the DataContract work?

    Thanks a lot!

    Friday, July 05, 2013 5:04 PM

Answers

  • I don't think the SuspensionManager can serialize anything more complex than simple data types.

    The solution is to either serialize your object to Platform::String yourself and pass this through the navigate method and deserialize on the other side

    or

    Globalize your list of MyClasses at the app level and pass an index to the list through the navigate method.

    • Marked as answer by encoderuser Friday, July 05, 2013 5:23 PM
    Friday, July 05, 2013 5:16 PM

All replies

  • I don't think the SuspensionManager can serialize anything more complex than simple data types.

    The solution is to either serialize your object to Platform::String yourself and pass this through the navigate method and deserialize on the other side

    or

    Globalize your list of MyClasses at the app level and pass an index to the list through the navigate method.

    • Marked as answer by encoderuser Friday, July 05, 2013 5:23 PM
    Friday, July 05, 2013 5:16 PM
  • Really? Thanks.
    Friday, July 05, 2013 5:23 PM
  • This might be fixed for Windows 8.1.  See this.
    Friday, July 05, 2013 5:38 PM