-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonSerializer throws AccessViolationException for struct with field initializers #62983
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionDeserialize a struct with field initializer causes Reproduction StepsJsonSerializer.Deserialize<Foo>("{}");
public struct Foo
{
public float A = 1;
} Expected behaviorThe struct is deserialized successfully with the field initialized using the default field initializer. Actual behaviorThrows this exception:
Regression?No response Known WorkaroundsNo response Configuration.NET SDK Version: 6.0.101 Other informationNo response
|
Checked JIT fails with
I guess it's slightly confused with the input IL which creates a Foo struct but is reported to have a ref-type return type 🤔
|
I suspect it's JSON's |
So Explicit parameterless ctor also reproduces the AVE: using System.Text.Json;
JsonSerializer.Deserialize<Foo>("{}");
public struct Foo
{
public float A;
public Foo()
{
A = 42;
}
} |
Thanks for the fix! |
Description
Deserialize a struct with field initializer causes
AccessViolationException
.Reproduction Steps
Expected behavior
The struct is deserialized successfully with the field initialized using the default field initializer.
Actual behavior
Throws this exception:
Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK Version: 6.0.101
Other information
No response
The text was updated successfully, but these errors were encountered: