question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source generator diagnostics are not showing up in VS Quick Info

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
eiriktsarpaliscommented, Dec 9, 2021

You reproduction is also producing the following warning:

CSC : warning SYSLIB1032: Derived 'JsonSerializerContext' type 'InnerJsonContext' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation.

And that is the root of your issue. While you have declared InnerJsonContext as partial its containing class is not partial. Once I mark Outer as partial the compiler errors go away.

0reactions
terrajobstcommented, Jan 4, 2022

You reproduction is also producing the following warning:

CSC : warning SYSLIB1032: Derived 'JsonSerializerContext' type 'InnerJsonContext' specifies JSON-serializable types. The type and all containing types must be made partial to kick off source generation.

And that is the root of your issue. While you have declared InnerJsonContext as partial its containing class is not partial. Once I mark Outer as partial the compiler errors go away.

Does this indicate that this should have really been an error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source generator diagnostics are not showing up in VS ...
Description For this sample: public class Outer { internal class Inner { public string?
Read more >
Make diagnostic errors reported by a C# source generator ...
Make diagnostic errors reported by a C# source generator appear in the Visual Studio editor - Stack Overflow.
Read more >
Source Generators
Source Generators is a C# compiler feature that lets C# developers inspect user code as it is being compiled. Source generators create new ......
Read more >
Incremental Roslyn Source Generators In .NET 6
Due to missing implementation in the DemoSourceGenerator , we cannot check whether our Source Generator is working correctly. To force the compiler to...
Read more >
C# Source Generators Tutorial - YouTube
Introduction to C# Source Generators, a comprehensive development guide ... Setup 07:34 Diagnostics 11:57 Reading Source 17:33 Visual Studio ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found