msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
834 stars 175 forks source link

Index out of bounds exception when trying to deserialize object with missing List property on iPad #199

Closed diopol closed 7 years ago

diopol commented 8 years ago

This simple scenario throws exception on iPad:

    public class Obj1
    {
        [MessagePackMember(0)]
        public string Id { get; set; }

        [MessagePackMember(1)]
        public List<string> Items { get; set; }
    }

    public class Obj2
    {
        [MessagePackMember(0)]
        public string Id { get; set; }

        // doesn't know about Items
    }

    void ThisMethodThrowsIndexOutOfBoundsException()
    {
        using (var memStream = new MemoryStream())
        {
            SerializationContext.Default.GetSerializer<Obj1>().Pack(memStream, new Obj1
            {
                Id = "1",
                Items = new List<string> { "a", "b" }
            });

            memStream.Seek(0, SeekOrigin.Begin);

            var serializer2 = SerializationContext.Default.GetSerializer<Obj2>();

            // this call throws
            Obj2 obj = serializer2.Unpack(memStream);
        }
    }

Works well in full .NET MsgPack Cli is installed from Nuget, version 0.8.0

yfakariya commented 8 years ago

Sorry for delay and thank you for repost. IndexOutOfBoundException means bug. I will investigate and fix it.

yfakariya commented 8 years ago

This is a versioning issue. Deserialization logic should ignore extra member in this scenario.

yfakariya commented 7 years ago

Fixed in 53d02ba