It makes sense to get this error, since the IModel property can refer to different classes, and there is no guarantee that all of them are Serializable.
OK, I tried, and we have:
Test system error, it works on my computer.
interface IFoo { } [Serializable] class CFoo : IFoo { } [Serializable] class Bar { public IFoo Foo { get; set; } }
Both Bar Serializes and Deserializes are excellent.
Bar b = new Bar(); b.Foo = new CFoo(); using (var s = new System.IO.MemoryStream()) { var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bf.Serialize(s, b); s.Position = 0; b = (Bar)bf.Deserialize(s); Console.WriteLine("OK"); }
So what is different from your IModel and Model ?
source share