The following code causes exception.
enum Enum
{
Item1,
Item2,
Item3
}
class ClassA
{
public Enum Enum { get; set; }
public bool Bool { get; set; }
}
class Program
{
static void Main(string[] args)
{
var classA = new ClassA
{
Bool = true,
Enum = Enum.Item2
};
var binarySerialize = new BinaryConverter();
var data = binarySerialize.Serialize(classA);
var classADeserialize = binarySerialize.Deserialize<ClassA>(data); **ArgumentException**
Console.ReadKey();
}
}
If the Bool property is defined to the top, there will be no exception, but Enum is not set in Item2
class ClassA
{
public bool Bool { get; set; }
public Enum Enum { get; set; }
}
If you add one more property to the end (example string property) there will be an exception.
class ClassA
{
public bool Bool { get; set; }
public Enum Enum { get; set; }
public string String { get; set; }
}