wpfcatel

Updating to Catel 5.0.0 -- Serialization problems


.NET 4.7.2, WPF

I have an old project which used Catel 4.4.0. I need to update it to the latest .NET and package versions, so I'm moving it to Catel 5.0.0 as a first step. (I will eventually move it to the latest version.)

My Models under Catel 4.4.0 where all derived from SavableModelBase which included serialization and validation. For 5.0.0, it looks like you can have a SavableModelBase or a ValidatableModelBase, but not both. I decided to change all my classes to use ValidatableModelBase as validation is significant in my project.

I searched for examples of Loading/Saving Models with Catel 5.0.0, but the few examples I found appeared to be using pre-5.0.0 code.

https://docs.catelproject.com/vnext/setup-deployment/update-guides/catel-5.0/ https://catelproject.atlassian.net/wiki/spaces/CTL/pages/15630363/Serializing+data+from+to+disk

I used to be able to use:

myModel.Save(myStream, SerializationMode.Xml);
MyModel model = MyModel.Load(myStream, SerializationMode.Xml);

but, of course, all that has changed with 5.0.0.

Does someone have a reference to loading and saving Models with Catel 5.0.0? Should I be doing this in generic Microsoft .NET code? My concern is I have users with existing data files which must be compatible with the updated software.

If you have any questions, please let me know.

thanks, randy


Solution

  • The SavableModelBase became just a wrapper with 5.0. The ModelBase uses ISerializer and you can simply pass in the models to the serializers (e.g. IXmlSerializer).

    I recommend to upgrade to 5.12 immediately, it will save you some headaches.