2

I have an app with 2 pages calendar.xaml(start page) and historystatistics.xaml. Error is thrown when I navigate to historystatistics and back to calendar and then try to terminate the app by the pulling down gesture. The mentioned error occurs at the SaveAsync function in OnSuspending of App.xaml.

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        CycleManager cycMan = CycleManager.Instance;
        var deferral = e.SuspendingOperation.GetDeferral();
        //TODO: Save application state and stop any background activity
        if (cycMan.Reset != true)
        {
            await Appname.Common.SuspensionManager.SaveAsync(); // **ERROR**
        }
        deferral.Complete();          
    }

It says

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code.

GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.

Where did I wrong? I did a simple navigation from historystatistics page from xaml like this

<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
8
  • Are you passing a parameter to the navigation? Notice that you can only pass serializable objects. May 24, 2013 at 12:57
  • Nope. No parameters are passed. I read in some forum that it can happen if i try to pass a complex parameter. I havent even written the goback function since it is the default Basic page and hence it contains the back button.
    – alfah
    May 24, 2013 at 13:17
  • So try overrighting the goback function and try to pass an empty string. May 24, 2013 at 13:21
  • @inxs base.GoBack(sender, e); ??
    – alfah
    May 24, 2013 at 13:24
  • just a regular overwriting. public void overwrite GoBack(sender, Eventargs) May 24, 2013 at 13:28

1 Answer 1

0

The problem is that SuspensionManager uses Frame.GetNavigationState() to get the history of the Frame. It then tries to serialize the navigation history to a string, unfortunately it has no way to know how to serialize custom complex types .

From MSDN :

Note The serialization format used by these methods is for internal use only. Your app should not form any dependencies on it. Additionally, this format supports serialization only for basic types like string, char, numeric and GUID types.

The best solution for this problem to rewrite the NavigationParameter or if you didn't want to save your app state just comment the line :

private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    //await SuspensionManager.SaveAsync();
    deferral.Complete();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.