简体   繁体   中英

DevExpress and SimpleMvvmToolkit - Serialization error

I have a DevExpress DxGrid bound to an ObservableCollection of viewmodels (based on SimpleMvvmToolkit). The viewmodel has 2 properties exposed by itself (a string and a boolean) and a few other properties are exposed by its base class (ViewModelDetailBase), one of them is the model behind the viewmodel.

Everytime I use the grid to modify the contents of one of the properties (eg the boolean value), I get an error saying "The type xxx cannot be serialized.." (xxx is the type of the Model) followed by the suggestion to use DataContractAttribute to circomvent the issue. I am not sure how and where to look for a solution. Maybe I should read up on it, but why is serialization needed here??

Anyway, I hope you can shed a light on this. I'd appreciate some pointers to get me looking in the right direction.

edit: Since the situation is too intricate to post the relevant code here, I made a sandbox project that reproduces the error. You can find it via this WeTransfer link .

Best regards, ~Rob

Thanks to great help of the Simple MVVM Toolkit community I found out that the solution was simple.

In Simple MVVM Toolkit, A viewmodel needs to be serializable because it gets cloned. This is to easily roll-back data when an action is canceled. The reason my viewmodel could not be cloned whas because its "model" property was missing a default (parameter-less) constructor.

There's no need to decorate the viewmodel and its properties with [DataContract] or [DataMember] .

I hope this helps others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM