dotnet/runtime

Issue diagnostic warnings when custom JsonSerializerContext types don't indicate serializable types

Open

#58,698 opened on 2021年9月5日

GitHub で見る
 (9 comments) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.Text.Jsonenhancementhelp wantedsource-generator

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

When my custom serialiazer context class has zero JsonSerializable attributes, I get an error message which does not help me understand what the problem is.

I simply get the dreaded:

CS0534	'MyJsonSerializerContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'

I do not get any additional information to help me realize that I forgot to add JsonSerializable attributes to my custom class. It would be extremely helpful to get an error message similar to Your custom serializer context class must have at least one JsonSerializable attribute.

Repro:

public static class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World!");
    }
}

// Notice there are no JsonSerializable attributes here.
internal partial class MyJsonSerializerContext : JsonSerializerContext
{
}

As an aside: Is there a way to get more detailed information when something goes wrong with the code generator? Does it generate a log somewhere?

コントリビューターガイド