-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
area-System.Text.JsonuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Description
JsonSourceGenerator does not correctly handle C# verbatim identifiers and confuses them during code generation.
Reproduction Steps
$ cat <<EOF | dotnet run -
using System.Text.Json;
using System.Text.Json.Serialization;
Console.Write(JsonSerializer.Deserialize("""{"else":{}}""",Ctx.Default.A));
[JsonSerializable(typeof(A))] partial class Ctx : JsonSerializerContext;
record A { public A? @else { get; init; } }
EOF
~/System.Text.Json.SourceGeneration/System.Text.Json.SourceGeneration.JsonSourceGenerator/Ctx.A.g.cs(41,9): error CS8802: Only one compilation unit can have top-level statements.
The build failed. Fix the build errors and run again.Expected behavior
$ cat <<EOF | dotnet run -
using System.Text.Json;
using System.Text.Json.Serialization;
Console.Write(JsonSerializer.Deserialize("""{"else":{}}""",Ctx.Default.A));
[JsonSerializable(typeof(A))] partial class Ctx : JsonSerializerContext;
record A { public A? @else { get; init; } }
EOF
A { else = A { else = } }Actual behavior
.
Regression?
No response
Known Workarounds
$ cat <<EOF | dotnet run -
#:property PublishAot=false
using System.Text.Json;
Console.Write(JsonSerializer.Deserialize<A>("""{"else":{}}"""));
record A { public A? @else { get; init; } }
EOF
A { else = A { else = } }$ cat <<EOF | dotnet run -
using System.Text.Json;
using System.Text.Json.Serialization;
Console.Write(JsonSerializer.Deserialize("""{"else":{}}""",Ctx.Default.A));
[JsonSerializable(typeof(A))] partial class Ctx : JsonSerializerContext;
record A { [JsonPropertyName("else")] public A? Else { get; init; } }
EOF
A { Else = A { Else = } }Configuration
$ dotnet --version
10.0.100Other information
No response
Copilot
Metadata
Metadata
Assignees
Labels
area-System.Text.JsonuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner