-
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
Ensure source generated metadata properties are read-only. #76540
Ensure source generated metadata properties are read-only. #76540
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsProposed fix for #76535.
|
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
Show resolved
Hide resolved
Marking as ready-for-review, since we're probably favoring this approach over #76683. |
FYI @ericstj @jeffhandley |
...System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/JsonSerializerContextTests.cs
Outdated
Show resolved
Hide resolved
...System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/JsonSerializerContextTests.cs
Outdated
Show resolved
Hide resolved
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3229345791 |
@eiriktsarpalis backporting to release/7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Ensure source generated metadata properties are read-only.
Applying: Use RemoteExecutor when modifying static metadata.
Applying: Add testing validating that interface metadata is mutable.
Applying: Update error messages
Using index info to reconstruct a base tree...
M src/libraries/System.Text.Json/src/Resources/Strings.resx
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Text.Json/src/Resources/Strings.resx
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/Resources/Strings.resx
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0004 Update error messages
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
d068593
to
66ad2e8
Compare
Rebased & squashed changes to ensure the changes from #76869 are incorporated in CI runs. |
Per API review, we altered this fix to move The APIs are now more discoverable by users
Other than where this surfaces in the API, the implementation of the fix remains the same. This ensures users don’t stumble upon mutations when we don’t expect it, leading to unexpected results that are difficult to diagnose. |
@bartonjs Can you take a look at the X509 test failures on this please? I can't imagine the failures are related, but I also don't see any existing issues for these specific failures. On the surface, I wonder if this is one of those situations where Window is spontaneously failing and we've only been able to repro this on CI machines. Note that the release/7.0 version of the PR had solid green on the CI and it was merged. |
|
It's based on precedent from equivalent APIs in |
Appears to be this error. I'm guessing it's caused by a service not running on the particular test machine. |
Fixes #76535. Note that this introduces the following API that is used by the source generator.
While we don't expect user code will directly invoke either of these APIs, their presence is beneficial. When the metadata is locked, mutation members throw exceptions, and customers can anticipate that possibility by seeing
IsReadOnly
and inspecting its value and when it changes. There is a possibility user code will begin referencingMakeReadOnly
in scenarios we don't anticipate, and/or that we'll want to introduce scoped or validated read-only states in the future. If those scenarios arise, it's possible the shape introduced here won't be ideal. But we have mitigation approaches if needed.Should be backported to
release/7.0
.Fix #76893.