0

I'm working in windows phone 8 application with MVVM pattern. I need to preserve page state when my app going to suspend. So I'm using State dictionary to store my viewmodel its working fine, But when I try to store viewmodel with parameter wise constructor following error will be occurred.

Type 'ViewModel' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.

Sivakumar
  • 345
  • 4
  • 14
  • It's a part of WCF technologies. Take a look at this post: http://stackoverflow.com/questions/4836683/when-to-use-datacontract-and-datamember-attributes – Cristian E. Oct 03 '13 at 11:14

1 Answers1

0

If you pass an object to the State dictionary it will be serialized with the [Xml]DataContractSerializer and that requires a public, parameterless constructor.

If you're not able, or unwilling, to add such a constructor then you'll need to handle the serialization and deserialization of the object yourself and add the serialized data (the string) to the dictionary instead.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143