-
-
Notifications
You must be signed in to change notification settings - Fork 754
Open
Description
Bug description
Typeless serializer fails to serialize simple type, unless fields are prefixed with "_"
Repro steps
public class TempTests
{
private static Fixture Fixture = new Fixture();
[Fact]
public void Should_Serialize()
{
var expected = Fixture.Create<TestInfo>();
var binary = MessagePackSerializer.Typeless.Serialize(expected);
// var current = MessagePackSerializer.Typeless.Deserialize(binary);
// current.ShouldDeepEqual(expected);
}
public struct TestInfo
{
// if fields are prefixed with "_" then it works fine
private Guid typeId;
private Guid levelId;
public TestInfo(
Guid typeId,
Guid levelId)
{
this.typeId = typeId;
this.levelId = levelId;
}
public Guid TypeId
{
get => this.typeId;
set
{
this.typeId = value;
}
}
public Guid LevelId
{
get => this.levelId;
set
{
this.levelId = value;
}
}
}
Expected behavior
Should be able to serialize simple types without requiring that fields are prefixed with "_"
Actual behavior
Serialization fails with message
MessagePack.MessagePackSerializationException
Failed to serialize System.Object value.
at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
at MessagePack.MessagePackSerializer.Serialize[T](T value, MessagePackSerializerOptions options, CancellationToken cancellationToken)
at MessagePack.MessagePackSerializer.Typeless.Serialize(Object obj, MessagePackSerializerOptions options, CancellationToken cancellationToken)
at SeatGeek.Open.SmartCaching.Tests.Serializers.MsgPackSerializerTests.TempTests.Should_Serialize() in /Users/edvardpitka/code/src/gitlab.service.seatgeek.mgmt/consumer/peakpass/SeatGeek.Open.SmartCaching.Tests/Serializers/MsgPackSerializerTests/TempTests.cs:line 21
System.TypeInitializationException
The type initializer for 'FormatterCache`1' threw an exception.
at MessagePack.Resolvers.DynamicContractlessObjectResolverAllowPrivate.GetFormatter[T]()
at MessagePack.Resolvers.TypelessContractlessStandardResolver.ResolverCache.GetFormatterCore[T]()
at MessagePack.Resolvers.CachingFormatterResolver.GetFormatter[T]()
at MessagePack.Resolvers.TypelessContractlessStandardResolver.GetFormatter[T]()
at MessagePack.FormatterResolverExtensions.GetFormatterDynamic(IFormatterResolver resolver, Type type)
at MessagePack.FormatterResolverExtensions.GetFormatterDynamicWithVerify(IFormatterResolver resolver, Type type)
at MessagePack.Formatters.TypelessFormatter.Serialize(MessagePackWriter& writer, Object value, MessagePackSerializerOptions options)
at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
- Version used: MessagePack 2.5.108
- Runtime: .NET Core 6
Metadata
Metadata
Assignees
Labels
No labels