lrascao / protobuf-net

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

AsReferenceDefault does not work in certain cases with derived classes #434

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Test program as follows:

    [ProtoContract(AsReferenceDefault = true)]
    [ProtoInclude(10, typeof(Derived))]
    public class Base
    {
        [ProtoMember(1)]
        public Derived DerivedInstance;
    }

    [ProtoContract(AsReferenceDefault = true)]
    public class Derived : Base
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            var schema = RuntimeTypeModel.Default.GetSchema(typeof(Derived));
            Console.Out.WriteLine(schema);
        }
    }

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

I expect that the DerivedInstance field will be serialized by reference, but it 
is not. Program output is:

    message Base {
       optional Base DerivedInstance = 1;
       // the following represent sub-types; at most 1 should have a value
       optional Derived Derived = 10;
    }
    message Derived {
    }

Interestingly, if you ask for the schema for typeof(Base) rather than 
typeof(Derived) it is correct.

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

Version r668, VS2012, Windows 7 x64

- John Hall <john@xjtag.com>

Original issue reported on code.google.com by j...@jdh28.co.uk on 14 Mar 2014 at 4:06