Mahdi
Mahdi

Reputation: 1827

Application crash after suspending when the navigation parameter is a complex object

I'm working on a Windows 8 application ( Windows Store Application). I have a page with two navigation parameters:

if (navigationParameter is int)
{
     BindByBoxId(navigationParameter);
}
else if (navigationParameter is Word)
{
     BindByWordObject(navigationParameter as Word);
}

when the application enters to the page with integer as the navigation parameter everything is well after the application goes to suspend mode, but, when the navigation parameter is a word object (complex object) the application crashes when the OnSuspendingevent handler runs.

by investigating more the problem in following part of code in SuspensionManagerclass :

 private static void SaveFrameNavigationState(Frame frame)
 {
      var frameState = SessionStateForFrame(frame);
      frameState["Navigation"] = frame.GetNavigationState();
 }

the problem is `GetNavigationState. The description of the method in MSDN mentions this fact that:

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.

please advice me how to solve my problem.

Upvotes: 1

Views: 455

Answers (1)

Nate Diamond
Nate Diamond

Reputation: 5575

I realize this is quite late, but here's the resolution for future questers:

You need to serialize the object yourself. You can use something like the DataContractSerializer, XmlSerializer, or one of the many great libraries like Json.NET. Then, the saved object is just a string. On load state, you deserialize the string and you are good to go.

Upvotes: 1

Related Questions