amoraller / protobuf-net

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

Unknown wire type error from multiple writes #320

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Mark,

I found that writing multiple items to the same stream causes an "unknown 
wire-type" error.

http://stackoverflow.com/questions/2152978/using-protobuf-net-i-suddenly-got-an-
exception-about-an-unknown-wire-type/12403068#12403068

Here is the sample that will demonstrate the problem

    [ProtoContract]
    public class Data1
    {
        [ProtoMember(1, IsRequired=true)]
        public int A { get; set; }
    }

    [ProtoContract]
    public class Data2
    {
        [ProtoMember(1, IsRequired = true)]
        public string B { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var d1 = new Data1 { A = 1};
            var d2 = new Data2 { B = "Hello" };
            var ms = new MemoryStream();
            Serializer.Serialize(ms, d1); 
            Serializer.Serialize(ms, d2);
            ms.Position = 0;
            var d3 = Serializer.Deserialize<Data1>(ms); // This will fail
            var d4 = Serializer.Deserialize<Data2>(ms);
            Console.WriteLine("{0} {1}", d3, d4);
        }
    }

I was using protobuf-net 2.0.0.480 on Windows 7 64 bit.

chriseyre2000@gmail.com

Original issue reported on code.google.com by chriseyr...@gmail.com on 16 Sep 2012 at 9:02

GoogleCodeExporter commented 9 years ago
This is not an error as such, and is fully described here: 
http://stackoverflow.com/a/12403068/23354

Original comment by marc.gravell on 18 Sep 2012 at 9:09