Compile Error When Using Default Interface Implementation of IMessagePackFormatter<T> with Source Generator
まだ誰も着手していません。
評価
調査の方向性
提供された .NET 8 の再現コードから始め、MessagePack ソースジェネレーターによる formatter の検出と、CustomMessageFormatter のインターフェイスメソッド解決を追跡してください。IMessagePackFormatter の既定実装が生成コードでどのように表現されるかを確認し、示されている formatter パターンの回帰テストカバレッジを追加してください。プロジェクトがコンパイルされ、生成された serializer が継承された Serialize メソッドと Deserialize メソッドを受け入れれば完了です。
索引モデルが issue の本文から書いたものです。
説明
When implementing IMessagePackFormatter via an interface that provides default implementations for Serialize and Deserialize, a compile-time error occurs if a concrete formatter class relies on those default methods and is used with the MessagePack source generator.
[MessagePackObject]
public class CustomMessage
{
[Key(0)]
public string Content { get; set; } = "";
[Key(1)]
public string CustomData { get; set; } = "";
}
public interface ICustomSerializableFormatter<TFrom, TTo> : IMessagePackFormatter<TFrom>
{
TTo ConvertTo(TFrom value);
TFrom ConvertFrom(TTo value);
void IMessagePackFormatter<TFrom>.Serialize(ref MessagePackWriter writer, TFrom value, MessagePackSerializerOptions options)
{
if (value == null)
{
writer.WriteNil();
return;
}
options.Resolver.GetFormatterWithVerify<TTo>().Serialize(ref writer, ConvertTo(value), options);
}
TFrom IMessagePackFormatter<TFrom>.Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
return ConvertFrom(options.Resolver.GetFormatterWithVerify<TTo>().Deserialize(ref reader, options));
}
}
public class CustomMessageFormatter : ICustomSerializableFormatter<CustomMessage, (string, string)>
{
public (string, string) ConvertTo(CustomMessage value)
{
return (value.Content, value.CustomData);
}
public CustomMessage ConvertFrom((string, string) value)
{
return new CustomMessage
{
Content = value.Item1,
CustomData = value.Item2
};
}
}
If CustomMessageFormatter is assigned as the custom formatter for CustomMessage (e.g. via MessagePackFormatter attribute or resolver registration), the MessagePack source generator fails with a compile-time error.
Although the interface provides default implementations for Serialize and Deserialize, and the implementing class doesn't need to override them explicitly, the source generator does not recognize those default methods and treats them as missing.
✅ Expected Behavior
The source generator should recognize and support default interface method implementations of IMessagePackFormatter, allowing formatter classes to inherit them without explicitly overriding the methods.
💡 Additional Info
This issue occurs outside of Unity, in a standard .NET 8 project.
MessagePack C# version: (3.14)
.NET SDK version: (.net 8)
The issue seems to stem from the generator not handling default interface method resolution correctly.
- 主要言語
- C#
- スター
- 6.8k
- フォーク
- 783
- 平均マージ
- 19時間 47分
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MessagePack-CSharp/MessagePack-CSharp のほかの issue
-
SerializableMemberTypeAnalyzer throws AD0001 when any referenced assembly has an assembly-level attribute with a single array argument対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
MessagePack-CSharp/MessagePack-CSharp#2324 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
MessagePack-CSharp/MessagePack-CSharp#2276 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
MessagePack-CSharp/MessagePack-CSharp#2252 · コメント 3 件 ·
-
dynamic type fails sourcegenerator CS8785 'MessagePackGenerator' failed to generate source.対応中かも @1AbdullahButt が 13 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
MessagePack-CSharp/MessagePack-CSharp#2318 · コメント 2 件 ·
MessagePack-CSharp/MessagePack-CSharp の issue をすべて見る
似ている issue
-
type:task ux
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
elsa-workflows/elsa-foundation#5253 ·
メンテナーはふだん 1 日以内に返信