[Solved] C#, can’t serialize to binary


I figure out what the error is for those in future who might be banging their head wondering what went wrong. It’s actually really simple. A small typo actually. Too bad M$ have horrible error message that don’t really tell you where the error might have happened:

Simply replace this line:

public void GetObjectData(SerializationInfo info, StreamingContext context)
{
    Type myTypeObj = Type.GetType("Settings");
    foreach (FieldInfo p in myTypeObj.GetFields())
    {
        Object value = p.GetValue(null);
        info.AddValue(p.Name, value, p.GetType());
    }
}

With this:

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        Type myTypeObj = Type.GetType("Settings");
        foreach (FieldInfo p in myTypeObj.GetFields())
        {
            Object value = p.GetValue(null);
            info.AddValue(p.Name, value, value.GetType());
        }
    }

And that’s it! Everything serialize/de-serialize just fine. You can’t possibly guess where it went wrong with the error msg: * No map for Object ‘822476800’*.

Note: In the last line, p.GetType should be value.GetType

1

solved C#, can’t serialize to binary