Jason
Jason

Reputation: 245

Saving collection using PhoneApplicationService.Current.State

I'm trying to save a collection where a store a diagnostic log temporarily when navigating away from my app - I've looked at other sample code and it seems pretty basic as I've done below:

Saving:

PhoneApplicationService.Current.State["DiagnosticLog"] = DiagnosticLog;

Loading:

if (PhoneApplicationService.Current.State.ContainsKey("DiagnosticLog"))
  DiagnosticLog = (ObservableCollection<DiagnosticLogEntry>)
    PhoneApplicationService.Current.State["DiagnosticLog"];

However I get this error:

A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.dll

Any suggestions please?

Upvotes: 0

Views: 618

Answers (1)

Shahar Prish
Shahar Prish

Reputation: 4849

Usually, when this happens, it means you do not have a default public constructor on your Diagnostic class (or one of it's contained classes).

Upvotes: 4

Related Questions