Skip to content

ArgumentException when serializing a nested struct #189

@samcragg

Description

@samcragg

Using 0.8.0 (and 0.9.0-beta1) it looks like there's a problem with serializing nested structures, the following code (which is a simplified example of what we've got) produces this exception:

Exception: ArgumentException
Message: Field '_field' defined on type 'Example.NestedStruct' is not a field on the target object which is of type 'MsgPack.StreamPacker'.
StackTrace:
at System.Reflection.RtFieldInfo.CheckConsistency(Object target)
at System.Reflection.RtFieldInfo.InternalGetValue(Object obj, StackCrawlMark& stackMark)
at System.Reflection.RtFieldInfo.GetValue(Object obj)
at MsgPack.Serialization.EmittingSerializers.Generated.Example_NestedStructSerializer2.PackValueOf_field(Packer , NestedStruct )
at MsgPack.Serialization.PackHelpers.PackToArray[TObject](PackToArrayParameters1& parameter) at MsgPack.Serialization.EmittingSerializers.Generated.Example_NestedStructSerializer2.PackToCore(Packer , NestedStruct ) at MsgPack.Serialization.MessagePackSerializer1.PackTo(Packer packer, T objectTree)
at MsgPack.Serialization.EmittingSerializers.Generated.Example_OuterClassSerializer1.PackValueOfStruct(Packer , OuterClass )
at MsgPack.Serialization.PackHelpers.PackToArray[TObject](PackToArrayParameters1& parameter) at MsgPack.Serialization.EmittingSerializers.Generated.Example_OuterClassSerializer1.PackToCore(Packer , OuterClass ) at MsgPack.Serialization.MessagePackSerializer1.PackTo(Packer packer, T objectTree)
at MsgPack.Serialization.MessagePackSerializer`1.PackSingleObject(T objectTree)
at Example.Program.Main(String[] args)

using System; using System.Runtime.Serialization; using MsgPack.Serialization; namespace Example { [DataContract] public struct NestedStruct { [DataMember] private int _field; } [DataContract] public class OuterClass { [DataMember] public NestedStruct Struct { get; set; } } class Program { static void Main(string[] args) { var context = new SerializationContext(); context.GetSerializer<OuterClass>().PackSingleObject(new OuterClass()); } } } 

It looks like there's a problem with the generated code, but I'm not sure how to debug that part, sorry. If you change NestedStruct to a class then it works, however.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDetected as bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions