question

zipswich avatar image
0 Votes"
zipswich asked AryaDing-MSFT edited

Why does Frame.GetNavigationState() throw "GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate" occasionally on suspending?

         private void OnSuspending(object sender, SuspendingEventArgs e)
         {
 ...
            var deferral = e.SuspendingOperation.GetDeferral();
            string sState = (Window.Current.Content as Frame).GetNavigationState();
 ...
         }

The above code works fine most of the time, but throws the following exception occasionally:

System.Exception: Unspecified error

GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.
Stack Trace:
at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Void*) + 0xbe
at __Interop.ForwardComStubs.Stub_2[TThis](__ComObject, Int32) + 0x36
at Windows.UI.Xaml.Controls.Frame.GetNavigationState() + 0x18

I am wondering if anyone could shed some light on the possible causes of this. I am unable to reproduce this, but an app's analytics reports quite a few of this exception.




windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AryaDing-MSFT avatar image
1 Vote"
AryaDing-MSFT answered AryaDing-MSFT edited

Hi,

Welcome to Microsoft Q&A!

Derive from the official document, to enable frame state serialization using GetNavigationState, you must use only basic types for the navigation parameter, such as string, char, numeric, and GUID types. Otherwise GetNavigationState will throw an exception when the app suspends. The parameter can have other types if you do not use GetNavigationState.

In a word, if you use GetNavigationState method, you can’t pass complex objects using Frame.Navigate. As follows:

 this.Frame. Navigate(Type, Object); //this object can’t be a complex object.



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you. I noticed that before posting my question, but could not figure out what it meant exactly. Now, I have realized what it meant with the help of your answer. If an app navigates from page A to page B with a complex object, then closes, this exception will happen in OnSuspending().

0 Votes 0 ·