Dumping ViewModel into state on tombstoning fails as ViewModelBase does not have public paramaterless constructor

Oct 20, 2010 at 10:23 AM

Hi,

Thanks for this great project, I am using it in my WP7 app and my SL4 app. 

I have a problem - to handle tombstoning in my WP7 app I dump my whole viewmodel into the PhoneApplicationService state as per this blog post.

This fails as all my VMs inherit from ViewModelBase which does not have a public parameterless constructor defined and therefore cannot be serilizable. I know I can edit the source but I was just wondering if this is by design or if it could be changed in the future (I am not a serialization or MVVM guru!)

http://www.imaginativeuniversal.com/blog/post/2010/09/12/Patterns-of-Windows-Phone-Architecture-Part-III.aspx

http://stackoverflow.com/questions/3976170/issue-with-mvvmlight-viewmodelbase-public-parameterless-constructor-in-inherited

Oct 22, 2010 at 2:19 AM

Laurent posted a reply to this here.

Nov 14, 2010 at 8:38 PM
Edited Nov 14, 2010 at 8:40 PM

I just hit a different manifestation of this same issue in my normal Silverlight 4 app trying to save ViewModels to IsolatesStorage. It took me a while to realise the issue due to misleading error messages from SL. You can read more about it here (check my answer)

http://stackoverflow.com/questions/4175956/is-there-a-size-limit-of-16k-for-silverlight-localsettings-isolatedstoragesettin/4179563#4179563

So the work-around is to download the ViewModelBase class and mark it as public... hopefully this can be considered in a future release. I have found the need to save my VM to disk on 2 different projects now - I am actually surprised no one has run into this issue before trying to persist ViewModels?