This project has moved and is read-only. For the latest updates, please go here.

GalaSoft.MvvmLight.ViewModelBase and DataContractAttribute

Apr 11, 2011 at 3:45 PM

Hi Guys,

I believe 'GalaSoft.MvvmLight.ViewModelBase' lucks of DataContractAttribute.
Sometimes you need this. For example if you link your model classes onto WebProject in order to reuse model implementation, then it is impossible to serialiaze that object.

See example solution:

SL project: class Person: ViewModelBase {}  //automatically generated when added serviceReference and referenced in ModelsProject
WebProject:   class Person  //Linked to ModelsProject. I create Person class here, from DB/other sources and it should be serializable.
ModelsProject:  classPerson: ViewModelBase {}

Idea of this solution to move stupid/expensive job of creating Person object onto Server, and in client only assign Person = WebReference.Person

So in this scenario it is impossible inherit from 'GalaSoft.MvvmLight.ViewModelBase' in ModelsProject, as

Type 'Models.Person' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute.  Consider marking the base type 'GalaSoft.MvvmLight.ViewModelBase' with DataContractAttribute or SerializableAttribute, or removing them from the derived type.

 Another argument will be Prism MVVMBaseClass has this attribute.

May 10, 2011 at 5:23 PM


Sorry for the delayed reply.

This is a good point. I will check it out.



Jan 25, 2013 at 8:25 PM

Has there been any progress on this?