End Google Ads 201810 - BS.net 01 --> Hi! I trying to use DataContractSerializer to save objects with crossreference. It´s two lists of objects.

I doesn´t get a error but even though the file is created it does´t work to get it back.

Maybe it´s better to use BinaryFormatter?

Some of my code:

DataContractSerializer xs = new DataContractSerializer(typeof(List)); DataContractSerializer xs2 = new DataContractSerializer(typeof(List)); Book-class: [KnownType(typeof(FaktaBok))] [KnownType(typeof(BarnBok))] [KnownType(typeof(SportBok))] [DataContractAttribute()] public class Book { [DataMember] protected int isbn = 0; [DataMember] protected string titel = null; [DataMember] protected string author; [DataMember] protected int price; [DataMember] protected String isType = null; [DataMember] protected Kund biblioteksKund = null; One derived class: [DataContractAttribute()] public class SportBok : Bok { [DataMember] private string sport; Serialize: using (Stream s = File.Create(path)) { xs.WriteObject(s, CustomerList); } using (Stream s2 = File.Create(path2)) { xs2.WriteObject(s2, BookList); } DeSerialize: if (File.Exists(path)) { using (Stream s = File.OpenRead(path)) { CustomerList = (List)xs.ReadObject(s); } } if (File.Exists(path2)){ using (Stream s2 = File.OpenRead(path2)) { BookList = (List)xs2.ReadObject(s2); }}