anerjan / protobuf-net

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

Error serializing ProtoMembers with DynamicType set to true #174

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
dasblinkenlight, at hotmail, dot com
==============

What steps will reproduce the problem?
1. Run unit test pasted at the bottom of this report.

What is the expected output? What do you see instead?
The test should pass; I see this stack trace instead:

System.ArgumentOutOfRangeException : Specified argument was out of the range of 
valid values.
Parameter name: index
at ProtoBuf.Meta.BasicList.Node.get_Item(Int32 index) in 
C:\Dev\protobuf-net\protobuf-net\Meta\BasicList.cs: line 79
at ProtoBuf.Meta.BasicList.get_Item(Int32 index) in 
C:\Dev\protobuf-net\protobuf-net\Meta\BasicList.cs: line 44
at ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 key, Object value, 
ProtoWriter dest) in RuntimeTypeModel.cs: line 351
at ProtoBuf.ProtoWriter.WriteObject(Object value, Int32 key, ProtoWriter 
writer) in ProtoWriter.cs: line 35
at ProtoBuf.BclHelpers.WriteNetObject(Object value, ProtoWriter dest, Int32 
key, Boolean dynamicType, Boolean asReference) in BclHelpers.cs: line 427
at ProtoBuf.Serializers.NetObjectSerializer.Write(Object value, ProtoWriter 
dest) in NetObjectSerializer.cs: line 41
at ProtoBuf.Serializers.TagDecorator.Write(Object value, ProtoWriter dest) in 
C:\Dev\protobuf-net\protobuf-net\Serializers\TagDecorator.cs: line 50
at ProtoBuf.Serializers.PropertyDecorator.Write(Object value, ProtoWriter dest) 
in C:\Dev\protobuf-net\protobuf-net\Serializers\PropertyDecorator.cs: line 46
at ProtoBuf.Serializers.TypeSerializer.Write(Object value, ProtoWriter dest) in 
C:\Dev\protobuf-net\protobuf-net\Serializers\TypeSerializer.cs: line 134
at ProtoBuf.Meta.RuntimeTypeModel.Serialize(Int32 key, Object value, 
ProtoWriter dest) in RuntimeTypeModel.cs: line 351
at ProtoBuf.Meta.TypeModel.SerializeCore(ProtoWriter writer, Object value) in 
TypeModel.cs: line 138
at ProtoBuf.Meta.TypeModel.Serialize(Stream dest, Object value) in 
TypeModel.cs: line 154
at ProtoBuf.Serializer.Serialize(Stream destination, T instance) in 
Serializer.cs: line 68

Debugging the code reveals that the key passed in is -1, the way it's supposed 
to be for dynamic types (NetObjectSerializer.cs, line 16: this.key = 
dynamicType ? -1 : key;)
Here is the line where it breaks when key == -1:
((MetaType)types[key]).Serializer.Write(value, dest);

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

I pulled and built the read-only trunk from svn.

Please provide any additional information below.

Here is the body of the unit test that exposes the error:

        [Test]
        public void TestDynamic() {
            var myVal = new TestProto {Value = true};
            byte[] serialized;
            using (var ms = new MemoryStream()) {
                Serializer.Serialize(ms, myVal);
                serialized = ms.ToArray();
            }
            Assert.That(serialized, Is.Not.Null);
        }

        [ProtoContract]
        public class TestProto {
            [ProtoMember(1, DynamicType = true)]
            public object Value { get; internal set; }
        }

Original issue reported on code.google.com by skali...@gmail.com on 25 May 2011 at 3:47

GoogleCodeExporter commented 9 years ago
This seems to have already been fixed by ongoing tweaking of DynamicType

Original comment by marc.gravell on 13 Jun 2011 at 8:42