davideuler / protobuf-net

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

Serializer.Serialize<T>(XmlWriter, T) produces empty string in XmlWriter #147

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
kreso@oasys.com
==============

What steps will reproduce the problem?
        [ProtoContract, DataContract, Serializable]
        public class TestClass : IXmlSerializable
        {
            [ProtoMember(1), DataMember]
            public string SomeString { get; set; }

            XmlSchema IXmlSerializable.GetSchema() { return null; }
            void IXmlSerializable.ReadXml(XmlReader reader) { Serializer.Merge(reader, this); }
            void IXmlSerializable.WriteXml(XmlWriter writer) { Serializer.Serialize(writer, this); }
        }
        [ProtoContract, DataContract, Serializable]
        public class ParentClass : IXmlSerializable
        {
            [XmlElement]
            [ProtoMember(1), DataMember]
            public TestClass TestProperty { get; set; }

            XmlSchema IXmlSerializable.GetSchema() { return null; }
            void IXmlSerializable.ReadXml(XmlReader reader) { Serializer.Merge(reader, this); }
            void IXmlSerializable.WriteXml(XmlWriter writer) { Serializer.Serialize(writer, this); }

            public ParentClass() { TestProperty = new TestClass(); }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder builder = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings() { ConformanceLevel = ConformanceLevel.Auto };
            ParentClass parent = new ParentClass() { TestProperty = new TestClass() { SomeString = "foo", } };
            using (XmlWriter writer = XmlWriter.Create(builder, settings))
            {
                Serializer.Serialize<ParentClass>(writer, parent);
                writer.Flush();
                writer.Close();
            }
            string result = builder.ToString();

What is the expected output? What do you see instead?
Expected: string result should contain some form of XML
What do i get: string result is an empty string

What version of the product are you using? On what operating system?
protobuf-net-VS10.msi which was uploaded on Apr 14, 2010, downloaded on Dec 10, 
2010

Please provide any additional information below.
Breakpoints set in all IXmlSerializable functions of TestClass and ParentsClass 
are never hit.

Original issue reported on code.google.com by kpul...@gmail.com on 10 Dec 2010 at 1:55

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 2 Feb 2011 at 8:14