开发者

Issue with MVVMLight ViewModelBase public parameterless constructor in inherited base class for WP7 Tombstoning

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 p开发者_JAVA技巧arameterless 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜