I\'m trying to serialize and deserialize this ObservableCollection:
public class DataCollection : ObservableCollection
{
}
public class Data : I
After a little research it seems that there are problems when serializing ObservableCollection<T>
. See this blog post for more information.
In summary:
The problem is that the events have not been marked as non-serialized. Therefore, whenever you try to serialize an instance of ObservableCollection, you will also be attempting to serialize any event handlers. When you're using the collection for its primary scenario (data binding), you will have WPF controls attached to the events.
(Kent Boogaart)
Your Data
class will also suffer from similar problems; update your PropertyChanged
event like so:
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
As well as the updates already mentioned by other people, your Data
class should also be marked as Serializable
.