I tried this and it worked without problems.
[Serializable]
public class Foo
{
private int _prop1;
private string _prop2;
public string Prop2
{
get { return _prop2; }
set { _prop2 = value; }
}
public int Prop1
{
get { return _prop1; }
set { _prop1 = value; }
}
}
class Program
{
static void Main(string[] args)
{
Foo f = new Foo();
f.Prop1 = 1;
f.Prop2 = "test";
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, f);
// Holds the result of the serialization.
byte[] bytes = stream.ToArray();
// Deserialize the bytes array.
f = (Foo)formatter.Deserialize(new MemoryStream(bytes));
}
}