[ci-fix] Use DoNotWrapExceptions across ReflectionMemberAccessor Invoke paths#129212
Draft
github-actions[bot] wants to merge 9 commits into
Draft
[ci-fix] Use DoNotWrapExceptions across ReflectionMemberAccessor Invoke paths#129212github-actions[bot] wants to merge 9 commits into
github-actions[bot] wants to merge 9 commits into
Conversation
… accessors On Mono/tvOS (AOT environments), System.Text.Json uses ReflectionMemberAccessor which calls MethodInfo.Invoke() for property getters/setters. This wraps any exception thrown by the property in TargetInvocationException, unlike CoreCLR which uses IL-emitted delegates that propagate exceptions directly. The constructor delegates in the same class already unwrap TargetInvocationException; this commit adds the same treatment to CreatePropertyGetter and CreatePropertySetter using ExceptionDispatchInfo.Capture to preserve the original stack trace. Fixes the tvOS Mono test failure where AsyncEnumerableTests.SerializeAsyncEnumerable_PartialItemFailure tests expect InvalidOperationException but receive TargetInvocationException. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Closed
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
jkotas
reviewed
Jun 16, 2026
| { | ||
| return (TProperty)getMethodInfo.Invoke(obj, null)!; | ||
| #if NET | ||
| return (TProperty)getMethodInfo.Invoke( |
Member
There was a problem hiding this comment.
There are other Invoke method calls in this file. Do all of them need the same treatment?
Contributor
There was a problem hiding this comment.
Addressed in 6e9eede. I audited the other Invoke call sites in ReflectionMemberAccessor and updated them to use BindingFlags.DoNotWrapExceptions on NET (with existing non-NET compatibility paths preserved).
Open
3 tasks
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com>
Copilot
AI
changed the title
[ci-fix] Unwrap TargetInvocationException in ReflectionMemberAccessor property accessors
[ci-fix] Use DoNotWrapExceptions across ReflectionMemberAccessor Invoke paths
Jun 17, 2026
jkotas
reviewed
Jun 17, 2026
| parameters: new object[] { element! }, | ||
| culture: null); | ||
| #else | ||
| addMethod.Invoke(collection, new object[] { element! }); |
Member
There was a problem hiding this comment.
Should this catch and rethrow the exception like the other cases?
jkotas
reviewed
Jun 17, 2026
| @@ -130,6 +164,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate<T, TArg0, TArg1, T | |||
| { | |||
| throw e.InnerException ?? e; | |||
Member
There was a problem hiding this comment.
Should the pattern for catch and rethrow be consistent across all cases?
jkotas
reviewed
Jun 17, 2026
| if (accessor is null) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Failed to create union accessor for type '{entry.Key}' using method '{entry.Value}'."); |
Member
There was a problem hiding this comment.
This unrelated change. It should be left for separate PR (and tests should be added to cover it in that PR)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Workflow artifact: ci-fix
Artifact kind: help
Linked KBE: #128766
> [!NOTE]
> This is an AI/Copilot-generated fix updated after PR feedback and validated with targeted local build/test runs.
Root cause (best analysis)
AsyncEnumerableTests.SerializeAsyncEnumerable_*_PartialItemFailure_PriorItemsAreFullyWrittenfails on tvos-arm64 AllSubsets_Mono because the test expectsInvalidOperationExceptionbut receivesTargetInvocationException.The failing log line:
On Mono/tvOS (AOT environments),
System.Text.JsonusesReflectionMemberAccessor, where reflectionInvokecan wrap target exceptions. CoreCLR commonly usesReflectionEmitMemberAccessor, which propagates underlying exceptions directly.Attempted fix
Updated
ReflectionMemberAccessorto applyBindingFlags.DoNotWrapExceptionsonNETtargets across relevant reflectionInvokecall sites in the file (including property accessors and otherInvokeusages raised in review), while preserving non-NETcompatibility paths.Additional polish from feedback:
ReflectionEmitMemberAccessorfor add-method delegate behavior.What is unverified / where I need help
Validation
./build.sh clr+libs -rc release✅./build.sh clr+libs+host -rc release -lc release✅dotnet build src/libraries/System.Text.Json/src/System.Text.Json.csproj -c Release✅dotnet build /t:test src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj -p:Configuration=Release /p:XunitMethodName=System.Text.Json.Serialization.Tests.AsyncEnumerableTests_AsyncPipeSerializer.SerializeAsyncEnumerable_TopLevelValues_PartialItemFailure_PriorItemsAreFullyWritten✅Evidence
Help wanted
area-System.Text.Json):@StephenMolloy,@dotnet/area-system-text-jsonFiled by
ci-failure-fix. Comment here or on the workflow file to suggest changes;ci-failure-scan-feedbackreads in-scope feedback daily and opens (or updates) a PR with prompt edits.> [!WARNING]
>
> Generated by CI Outer-Loop Failure Fixer · ● 35M · ◷