Closed canton7 closed 2 years ago
Tagging subscribers to this area: @dotnet/area-system-text-json See info in area-owners.md if you want to be subscribed.
Author: | canton7 |
---|---|
Assignees: | - |
Labels: | `area-System.Text.Json`, `untriaged` |
Milestone: | - |
Duplicate of #61782.
Description
If the model passed to the
JsonSerializable
attribute on aJsonSerializerContext
subclass, theJsonSourceGenerator
generates invalid C#.Reproduction Steps
Create a new .NET 6 project with the contents:
Expected behavior
The source generator either produces a diagnostic saying that unbound generic models aren't supported, or produces valid C#.
Actual behavior
The source generator generates the following code in
MyJsonContext.GetJsonTypeInfo.g.cs
:MyJsonContext.ModelT.g.cs
also contains lots of instances of the same error, e.g.:Regression?
No
Known Workarounds
None
Configuration
.NET 6, Visual Studio 17.2.0 Preview 1.0.
Other information
Similar to https://github.com/dotnet/runtime/issues/66880, but I suspect the solution is different, since we can't create a
JsonTypeInfo
for an unbound generic type: it might be that the SG has to raise an error in this case, and require that all generic types passed toJsonSerializable
are bound.