-
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
[release/6.0] Handle parameterless ctors in structs in STJ's ReflectionEmitMemberAccessor #67901
[release/6.0] Handle parameterless ctors in structs in STJ's ReflectionEmitMemberAccessor #67901
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackport of #62989 Customer ImpactStructs with field initializations (C#10 feature) can cause NRE or AVE exceptions(crashes), minimal repro: JsonSerializer.Deserialize<Foo>("{}");
public struct Foo
{
public float A = 1;
} causes TestingThis PR adds tests Risklow cc @eiriktsarpalis @danmoseley
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Egor!
@EgorBo please check the test failure. Once it is good, we will request to @jeffschwMSFT for servicing consider. |
@RikkiGibson, @jcouv as Chuck is OOF |
|
||
public struct StructWithPropertyInit | ||
{ | ||
public long A { get; set; } = 42; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression we went back and made this an error in the same release we introduced field initializers on structs. It's now required to explicitly declare at least one constructor when field initializers are present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, totally forgot about it, but if I add an explicit parameterless constructor the test case will still be valid for the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @danmoseley would you also like to review?
Seems good to me. Where is the AV, though? Is that worth a separate fix, or does the JIT generally not promise to not AV on bad IL? |
Unverifiable IL can easily cause the runtime and JIT to lead to crashes. No guarantees with bad IL. |
is CI broken? |
@danmoseley this was missing the |
For that matter, if I look at all uses of At least this one seems broken too: Lines 277 to 312 in 5385962
|
I'm not sure it would meet the bar. It was never supported in DI before, so it isn't a regression. Also I haven't seen real user feedback needing it. You also don't typically gain anything by using ValueTypes in DI since you are always boxing/unboxing. So you might as well just use a So unless there is a need, I don't think it is necessary to backport to 6.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EgorBo @eiriktsarpalis @layomia @dotnet/area-system-text-json this PR is missing the OOB version bumping changes. Example: https://github.com/dotnet/runtime/pull/67104/files
In the S.T.Json.csproj, need to add this line:
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
And need to bump the ServicingVersion number to the next one:
<ServicingVersion>INCREASE ME</ServicingVersion>
@carlossanlop done. |
…ructs in STJ's ReflectionEmitMemberAccessor"
8e3cf74
to
f5c1cd5
Compare
Failures are unrelated: |
Backport of #62989
Customer Impact
Structs with field initializations (C#10 feature) can cause NRE or AVE exceptions(crashes), minimal repro:
causes
AccessViolationException
. There are two bug reports by users against 6.0: #62983 and #67781This PR fixes this behaviour.
Testing
This PR adds tests
Risk
low
cc @eiriktsarpalis @danmoseley