MessagePack-CSharp / MessagePack-CSharp/MessagePack-CSharp
MsgPack006 error when using custom formatter for generic types and MessagePack.Union
- Dominant language
- C#
- Stars
- 6.8k
- Forks
- 775
- Avg merge
- 3h 26m
- Merged PRs (30d)
- 6
Description
#### Bug description
MsgPack006 error when using generic class in custom formatter when class is GenericType and subType of a MessagePack.UnionAttribute marked abstruct class.
```
// ? MsgPack006 Type must be of IMessagePackFormatter: {0}
[MessagePackFormatter(typeof(MessagePackEmDataColumnFormatter<>))]
[MessagePackObject]
public partial class CustomDataColumn : DataColumnBase
{
[MessagePack.Key(0)]
public List Values { get; set; }
}
[Union(0, typeof(CustomDataColumn))]
[Union(1, typeof(CustomDataColumn))]
public abstract partial class DataColumnBase
{
}
public sealed class MessagePackEmDataColumnFormatter : IMessagePackFormatter>
{
public void Serialize(ref MessagePackWriter writer, CustomDataColumn value, MessagePackSerializerOptions options)
{
Console.WriteLine("Custom ObjectPoolDataColumnFormatter Serialize called");
}
public CustomDataColumn Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
Console.WriteLine("Custom ObjectPoolDataColumnFormatter Deserialize called");
var ____result = default(CustomDataColumn);
return ____result;
}
}
```
#### Repro steps
[MessagePackUnionAndFormatterDemo](https://github.com/hyabean/MessagePackUnionAndFormatter)
#### Expected behavior
The code should compile without error MsgPack006 .
#### Actual behavior
```
Severity Code Description Project File Line Suppression State Details
Error (active) MsgPack006 Type must be of IMessagePackFormatter: {0} MemoryPackDemo CustomDataColumn.cs 8
```
MsgPack006 error occured. Building can success if I suppress the warning
Version used: MessagePack v3.1.3
Runtime: .Net 8.0
#### Additional context
Contributor guide
Research direction
Start with the MessagePackUnionAndFormatterDemo reproduction and inspect CustomDataColumn.cs, especially the generic formatter and MessagePack.Union declarations that trigger MsgPack006. Trace the diagnostic during compilation and confirm the fix by building the demo without suppressing the warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100