NBMsgPack037: Async converters should override PreferAsyncSerialization
Custom converters that override the ReadAsync or WriteAsync methods should also override PreferAsyncSerialization and have it return true
.
Example violation
The following converter overrides the async methods but doesn't override PreferAsyncSerialization in order to indicate that its async methods are preferred:
internal class MyCustomConverter : MessagePackConverter<SomeCustomType>
{
public override SomeCustomType? Read(ref MessagePackReader reader, SerializationContext context)
{
throw new NotImplementedException();
}
public override void Write(ref MessagePackWriter writer, in SomeCustomType? value, SerializationContext context)
{
throw new NotImplementedException();
}
public override ValueTask<SomeCustomType?> ReadAsync(MessagePackAsyncReader reader, SerializationContext context)
{
return base.ReadAsync(reader, context);
}
public override ValueTask WriteAsync(MessagePackAsyncWriter writer, SomeCustomType? value, SerializationContext context)
{
return base.WriteAsync(writer, value, context);
}
}
Resolution
Simply add an override that returns true
:
public override bool PreferAsyncSerialization => true;