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

Make ObservableObject Serializable

Jun 16, 2015 at 5:18 PM
i just encountered the issue that I want to serialize my entire domain-model, where the elements derive from ObservableObject in order to make them usable in the UI as well.

Unfortunately the ObservableObject is missing the respective attributes (just 2 lines are missing). How about adding them in the next release?

The required changes are:
[Serializable] // This is new and required
public class ObservableObject : INotifyPropertyChanged
[field: NonSerialized]  // This is new and required
public event PropertyChangedEventHandler PropertyChanged;
Jun 17, 2015 at 8:02 AM

There are many ways to serialize an object, and supporting them all is not possible. For instance, ObservableObject can be serialized by JSON.NET without an issue.

What serializer exactly are you looking at?

Jun 17, 2015 at 9:19 AM
The basic BinaryFormatter from the System.Runtime.Serialization.Formatters.Binary.
using System.Runtime.Serialization.Formatters.Binary;

BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(targetStream, observableObjectToSerialize);