MsgPack006 error when using custom formatter for generic types and MessagePack.Union

Open
#2,193 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
backend

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.

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<T> : DataColumnBase
    {
        [MessagePack.Key(0)]
        public List<T> Values { get; set; }
    }

    [Union(0, typeof(CustomDataColumn<int>))]
    [Union(1, typeof(CustomDataColumn<double>))]
    public abstract partial class DataColumnBase
    {
    }


    public sealed class MessagePackEmDataColumnFormatter<T> : IMessagePackFormatter<CustomDataColumn<T>>
    {
        public void Serialize(ref MessagePackWriter writer, CustomDataColumn<T> value, MessagePackSerializerOptions options)
        {
            Console.WriteLine("Custom ObjectPoolDataColumnFormatter Serialize called");
        }

        public CustomDataColumn<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            Console.WriteLine("Custom ObjectPoolDataColumnFormatter Deserialize called");
            var ____result = default(CustomDataColumn<T>);
            return ____result;
        }
    }
Repro steps

MessagePackUnionAndFormatterDemo

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
Dominant language
C#
Stars
6.8k
Forks
778
Avg merge
22h 8m
Merged PRs (30d)
2

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MessagePack-CSharp/MessagePack-CSharp

All issues in MessagePack-CSharp/MessagePack-CSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.