-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonSerializerContext generated source breaks for property named "@event" #109854
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
|
Can confirm this is a bug which impacts all members using keyword identifiers. Here's a more involved example: public class @class
{
public @class(string @string)
{
this.@string = @string;
}
public string @string { get; set; }
}
[JsonSerializable(typeof(@class))]
public partial class MyContext : JsonSerializerContext; We should eventually try to update the generator so that it handles escaped identifiers more comprehensively. In the meantime, it should be possible to work around the issue by doing something like: public class ClickEvent
{
[JsonPropertyName("event")]
public required string Event { get; set; }
} |
fortunately i controlled both side of the protocol so i was able to work around by renaming the property. thanks! |
Description
Json source generator generates invalid code when a property name is a keyword, like @event
Reproduction Steps
Expected behavior
generated code does not cause compile errors
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: