leejw51 / protobuf-net

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

Interfaces as root objects cause problems #253

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?

This test fails. And after it fails any attempt to serialize the interface 
fails.

But if before this tests, serialization runs and it serializes the interface, 
not as a root object but as a member, then this test will pass.

        [Test]
        public void InterfaceAsRootObject()
        {
            //RuntimeTypeModel.Default.Add(typeof (ILesson5TestInteface1), true)
            //    .AddSubType(50, typeof(Lesson5TestClass2));

            ILesson5TestInteface1 instance = new Lesson5TestClass2
            {
                Name = "l5name2",
                Phone = "l5phone2"
            };
            var result = PassThroughProtobuf(instance);

            Assert.AreEqual("l5name2", result.Name);
            Assert.AreEqual("l5phone2", result.Phone);
        }

        [ProtoContract]
        public class Lesson5TestClass2 : ILesson5TestInteface1
        {
            [ProtoMember(1)]
            public string Name { get; set; }
            [ProtoMember(2)]
            public string Phone { get; set; }
        }

        [ProtoContract]
        [ProtoInclude(1000, typeof(Lesson5TestClass2))]
        public interface ILesson5TestInteface1
        {
            [ProtoMember(1)]
            string Name { get; set; }
            [ProtoMember(2)]
            string Phone { get; set; }
        }

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

The test should pass always.

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

r470

Original issue reported on code.google.com by j.go...@pamediakopes.gr on 24 Nov 2011 at 9:12