Skip to content

Consider sharing diagnostics issued by JSON source generator with reflection-based serializer #61262

@layomia

Description

@layomia

Many of the diagnostics issued by the JSON source generator are also applicable to the reflection-based serializer. For example, a type cannot contain multiple [JsonConstructor] applications. When the source generator is used, it logs a compile error when a type violates this expectation. A runtime exception is thrown in the reflection-based serializer instead.

Rather than having different behavior, we could package these diagnostic examinations into an analyzer that could be shared between the source generator and the reflection serializer, potentially giving the reflection serializer less validation work to do at runtime. We'd have to consider where this analyzer would live. There are a couple options

  • it could ship in the same assembly as the source generator (becoming the first analyzer to be shipped in the dotnet/runtime repo)
  • it could ship with the rest of the analyzers in https://github.com/dotnet/roslyn-analyzers

The source generator would be dependent on the analyzer, so we'd need to ship the analyzer in a manner that guarantees its visibility to the source generator.

cc @dotnet/area-system-text-json @jeffhandley

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionssource-generatorIndicates an issue with a source generator feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions