views:

39

answers:

1

I am handling tombstoning in Wp7 by dumping my ViewModel into the PhoneApplicationService state (see this link for more info).

My ViewModel (VM) inherits from the MVVM Light Toolkit (ViewModelBase) which has a protected parameterless constructor only.

This causes the serilization to fail with:

"The type 'GalaSoft.MvvmLight.ViewModelBase' cannot be deserialized in partial trust because it does not have a public parameterless constructor."

Excuse my ignorance but serialization is new to me - I think I understand why it's failing, but I am trying to think of ways around it. For example, can I mark the entire base class as non-serilizable or ignored like I do certain fields in classes ([IgnoreDataMember])? I don't need to store anything that is in this class.

Is there anyway around this? I don't want to edit the source of that assembly to mark it public instead of protected.

+2  A: 

Public default constructors in abstract classes are frowned upon by StyleCop, which is why I made the ViewModelBase one protected. As you found out, this however causes issues with serialization. This issue is more acute in WP7 where it is tempting to dump the whole vm in serialization for safe keeping.

Right now, the only fix I can propose is to implement your own viewmodelbase class. I will consider changing the constructor to public in a future release.

Cheers, Laurent

LBugnion
Thanks for the explanation Laurent, much appreciated! I have copied and changed it.
Rodney