Yes, the base class must also be serializable. Some simple test codes:
public class Animal { public Animal() { name = "Test"; } public string name { get; set; } } [Serializable] public class Cat : Animal { public string color {get; set;} } var acat = new Cat(); acat.color = "Green"; Stream stream = File.Open("test.bin", FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, acat); stream.Close();
When you try to serialize, you get this error:
Type 'SerializeTest.Animal' in Assembly 'SerializeTest, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null' is not marked as serializable.
edit - I notice that you did the same, but it worked for you. Do you have the code you used? This file is in .net 4, but I donโt think it has changed much between versions.
Tridus
source share