You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says, when there is a get-only property with an empty string as the default parameter in the constructor, the generator generates invalid C# code.
Reproduction Steps
Attempt to compile the following code:
using System.Text.Json.Serialization;publicclassTest{publicstringProperty{get;}publicTest(stringproperty=""){Property=property;}}[JsonSerializable(typeof(Test))]publicpartialclassContext:JsonSerializerContext{}
Expected behavior
The code compiles.
Actual behavior
1>C:\temp\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\Context.Test.g.cs(92,31,92,31): error CS1525: Invalid expression term '}'
It appears the generator is generating the following invalid object initializer:
Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.
Issue Details
Description
As the title says, when there is a get-only property with an empty string as the default parameter in the constructor, the generator generates invalid C# code.
Reproduction Steps
Attempt to compile the following code:
using System.Text.Json.Serialization;publicclassTest{publicstringProperty{get;}publicTest(stringproperty=""){Property=property;}}[JsonSerializable(typeof(Test))]publicpartialclassContext:JsonSerializerContext{publicstaticstringImplicit=>"World";}
Expected behavior
The code compiles.
Actual behavior
1>C:\temp\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\Context.Test.g.cs(92,31,92,31): error CS1525: Invalid expression term '}'
It appears the generator is generating the following invalid object initializer:
Description
As the title says, when there is a get-only property with an empty string as the default parameter in the constructor, the generator generates invalid C# code.
Reproduction Steps
Attempt to compile the following code:
Expected behavior
The code compiles.
Actual behavior
It appears the generator is generating the following invalid object initializer:
Regression?
No
Known Workarounds
Don't use empty strings as the default value.
Configuration
.NET 6.0.100.
Other information
No response
The text was updated successfully, but these errors were encountered: