I'm unable to serialize undecorated classes containing interface types using contractless or typeless serialization, getting:
MessagePack.MessagePackSerializationException: Failed to serialize Acme.TestClass value. ---> MessagePack.FormatterNotRegisteredException: Acme.IScheduler is not registered in resolver: MessagePack.Resolvers.CompositeResolver+CachingResolver
at at MessagePack.FormatterResolverExtensions.Throw(Type t, IFormatterResolver resolver)
at at Serialize(Byte[][] , Object[] , MessagePackWriter& , TestClass , MessagePackSerializerOptions )
at at MessagePack.Internal.AnonymousSerializableFormatter`1.Serialize(MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
at at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
Consider this class:
```c#
public class TestClass
{
public IScheduler Scheduler { get; set; }
}
public interface IScheduler
{
Guid Id { get; set; }
}
public class SchedulerA : IScheduler
{
public Guid Id { get; set; } = Guid.NewGuid();
}
And then attempting to serialize:
```c#
var test = new TestClass();
test.Scheduler = new SchedulerA();
// All these throw
var result1 = MessagePackSerializer.Typeless.Serialize(test);
var result2 = MessagePackSerializer.Serialize(test, MessagePack.Resolvers.ContractlessStandardResolver.Options);
var result3 = MessagePackSerializer.Serialize(test, MessagePack.Resolvers.TypelessContractlessStandardResolver.Options);
// Also throws
var resolver = CompositeResolver.Create(ContractlessStandardResolver.Instance, StandardResolver.Instance);
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
var result4 = MessagePackSerializer.Serialize(test, options);
I'd expect this to fail with the standard resolver since the types are not decorated with MessagePack attributes), but to suceed with contractless and/or typeless.
MessagePackSerializationException when calling Serialize
2.1.115 and 2.1.152Ability for contractless ser/deser of interface-, abstract-typed, and parent-class-typed properties seems like a critical feature.
Is there any way to achieve this? We wanted to switch from JSON to msgpack for saving app state but this is blocking us.
Since MessagePack has ability to record types during serialization it seems it could detect concrete types used in place of interfaces and derived classes and record those rather than what's known statically. Same goes for deserialization, use recorded types and not statically known through <T>
I have similar issue when migrating from NetDataContractSerializer.
Thank you for request and votes.
I've sent fix for this issue. #1078
Typeless support to serialize/deserialize interface/abstract object which not implements UnionAttribute.
Most helpful comment
Ability for contractless ser/deser of interface-, abstract-typed, and parent-class-typed properties seems like a critical feature.