Source generator diagnostics are not showing up in VS Quick Info
See original GitHub issueDescription
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
- Clone repro, open with Visual Studio.
- Open Net60Tests\Outer.cs
- Build without error, tests pass.
- 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:
- Created 2 years ago
- Comments:14 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You reproduction is also producing the following warning:
And that is the root of your issue. While you have declared
InnerJsonContext
as partial its containing class is not partial. Once I markOuter
as partial the compiler errors go away.Does this indicate that this should have really been an error?