anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

PB don't serialize superclass fields #315

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Comple and run following code

       private static void Main(string[] args)
        {
            var c = new C1()
                        {
                            c1 = new C2()
                                     {
                                         i = "iiii",
                                     },
                            c2 = new C3()
                                     {
                                         i = "iiii",
                                         j = "jjjj",
                                     }
                        };
            var ms = new MemoryStream();
            Serializer.Serialize(ms, c);
            ms.Seek(0, SeekOrigin.Begin);

            var o = Serializer.Deserialize<C1>(ms);

            ms.Seek(0, SeekOrigin.Begin);

            var str = new StreamReader(ms).ReadToEnd();

            Console.WriteLine(c.c2.i);
            Console.WriteLine(o.c2.i);
        }
    [ProtoContract]
    public class C1
    {
        [ProtoMember(1, DynamicType = false)] public C2 c1;
        [ProtoMember(2, DynamicType = false)] public C3 c2;
    }

    [ProtoContract]
    public class C2
    {
        [ProtoMember(1)] public string i;
    }

    [ProtoContract]
    public class C3 : C2
    {
        [ProtoMember(2)] public string j;
    }

What is the expected output? What do you see instead?

expected: iiii\niiii    got iiii\n

What version of the product are you using? On what operating system?
2.0.0.580   

Please provide any additional information below.

It don't pack supertype fields, even if dynamic types are off (DynamicType = 
false) 

If  endable Dynamic types -- icreates or C2 or C# but  still with same bug.

If i add ProtoInclude, than it serializes normally:

    [ProtoContract]
    [ProtoInclude(2,typeof(C3))]
    public class C2
    {
        [ProtoMember(1)] public string i;
    }

P.S. Attachig compilable file

Original issue reported on code.google.com by mart.bog...@gmail.com on 24 Aug 2012 at 3:49

Attachments: