Skip to content

Source generator diagnostics are not showing up in VS Quick Info #58435

@ChrisTorng

Description

@ChrisTorng

Description

For this sample:

public class Outer
{
    internal class Inner
    {
        public string? Name { get; init; }
    }

    [JsonSerializable(typeof(Inner))]
    internal partial class InnerJsonContext : JsonSerializerContext
    { }
}

[JsonSerializable(typeof(Outer.Inner))]
public partial class OuterInnerJsonContext : JsonSerializerContext
{ }

The OuterInnerJsonContext is ok, but InnerJsonContext has 3 compiler errors:

  • CS0534: 'Outer.InnerJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GeneratedSerializerOptions.get'
  • CS0534: 'Outer.InnerJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'
  • CS7036: There is no argument given that corresponds to the required formal parameter 'options' of 'JsonSerializerContext.JsonSerializerContext(JsonSerializerOptions?)'

But my requirement is make the Inner class private, because it should be hidden. So the OuterInnerJsonContext is not applicable.

I have a repro in Outer.cs showing this issue. Uncomment to see the compiler errors.

Reproduction Steps

  1. Clone repro, open with Visual Studio.
  2. Open Net60Tests\Outer.cs
  3. Build without error, tests pass.
  4. Uncomment all, then 3 errors appear on InnerJsonContext.

Expected behavior

It compiles without errors, and tests pass.

Actual behavior

InnerJsonContext has 3 compiler errors:

  • CS0534: 'Outer.InnerJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GeneratedSerializerOptions.get'
  • CS0534: 'Outer.InnerJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'
  • CS7036: There is no argument given that corresponds to the required formal parameter 'options' of 'JsonSerializerContext.JsonSerializerContext(JsonSerializerOptions?)'

Regression?

Don't know.

Known Workarounds

Make Inner class internal instead of private, then add OuterInnerJsonContext class outside of Outer class.

Configuration

.NET 6.0, Visual Studio 2022 17.1.0 Preview 1.0.

Other information

Don't know.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions