A strange thing happens when deserializing a boolean data element with inline initialization

when serializing a type with a logical element that is built into intialized to true - I always get the value as true when deserializing the object (obviously, the problem is that the actual value of the member was false before serialization), this does not happen in the opposite case (inline is initialized with the value false, and the value of the object is true - I also tried other manipulations and other types of data elements, and they all work fine).

here is the type:

[ProtoContract]
public class SomeObject
{
    public SomeObject() {}

    [ProtoMember(1)]
    private bool m_SomeMember = true;

    public bool SomeMember
    {
        get { return m_SomeMember; }
        set { m_SomeMember = value; }
    }
}

here is the code:

var stream = new MemoryStream();
var data = new SomeObject() {SomeMember = false};
Serializer.SerializeWithLengthPrefix<SomeObject>(stream, data , PrefixStyle.Base128);
stream.Position = 0;
var deserializedObject = Serializer.DeserializeWithLengthPrefix<SomeObject>(stream, PrefixStyle.Base128);

- SomeMember true. , ctor - , protobuf ctor ( , ), , HELP? (Marc?)

+5
1

protobuf-net ( false ). , :

[ProtoMember(1), DefaultValue(true)]
private bool m_SomeMember = true;

( RuntimeTypeModel.UseImplicitZeroDefaults) , .

+1

All Articles