A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neuecc/MessagePack-CSharp/issues/1134 below:

Deserialization of generic types fails due to inability to find property setters that use `init` · Issue #1134 · MessagePack-CSharp/MessagePack-CSharp · GitHub

Bug description

A generic type containing properties with an init accessor fails to serialize.

Repro steps

This type fails to serialize with the DynamicObjectResolver:

        [MessagePackObject]
        public class GenericPerson<T>
        {
            [Key(0)]
            public string Name { get; init; }
        }

This test fails:

        [Fact]
        public void RoundtripGenericClass()
        {
            var person = new GenericPerson<int> { Name = "bob" };
            byte[] msgpack = MessagePackSerializer.Serialize(person, MessagePackSerializerOptions.Standard);
            var deserialized = MessagePackSerializer.Deserialize<GenericPerson<int>>(msgpack, MessagePackSerializerOptions.Standard);
            Assert.Equal(person.Name, deserialized.Name);
        }
Expected behavior

Successful pass.

Actual behavior
  Message: 
    MessagePack.MessagePackSerializationException : Failed to deserialize MessagePack.Tests.DynamicObjectResolverTests+GenericPerson`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] value.
    ---- System.MissingMethodException : Method not found: 'Void GenericPerson`1.set_Data(!0)'.
  Stack Trace: 
    MessagePackSerializer.Deserialize[T](MessagePackReader& reader, MessagePackSerializerOptions options) line 251
    MessagePackSerializer.Deserialize[T](ReadOnlyMemory`1 buffer, MessagePackSerializerOptions options, CancellationToken cancellationToken) line 270
    DynamicObjectResolverTests.RoundtripGenericClass() line 321
    ----- Inner Stack Trace -----
       at MessagePack.Formatters.MessagePack_Tests_DynamicObjectResolverTests\.GenericPerson`1\[\[System_Int32\, System_Private_CoreLib\]\]Formatter1.Deserialize(MessagePackReader& reader, MessagePackSerializerOptions options)
    MessagePackSerializer.Deserialize[T](MessagePackReader& reader, MessagePackSerializerOptions options) line 246

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4