When I write a class like this, it gets serialized/deserialized perfectly.
[Serializable]
public class Post
{
public string Subject { get; set; }
}
When I use a private field however, deserialization of existing data fails. The following class no longer deserializes the subject
[Serializable]
public class Post
{
private string subj;
public string Subject { get { return subj; } set { subj = value; } }
}
I'm using the following piece of code
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter.Serialize(stream, posts);
and vice versa.
Can anybody explain why this happens?