Skip to content

[ci-fix] Needs review: Unwrap TargetInvocationException in AsyncEnumerable tests on tvOS Mono (refs #128766)#129654

Draft
github-actions[bot] wants to merge 2 commits into
mainfrom
ci-fix/async-enum-exception-128766-02b1f2343c2bf5c7
Draft

[ci-fix] Needs review: Unwrap TargetInvocationException in AsyncEnumerable tests on tvOS Mono (refs #128766)#129654
github-actions[bot] wants to merge 2 commits into
mainfrom
ci-fix/async-enum-exception-128766-02b1f2343c2bf5c7

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Workflow artifact: ci-fix
Artifact kind: help
Linked KBE: #128766

Note

This is an AI/Copilot-generated draft PR that attempts to fix the CI failure described in KBE #128766. It has NOT been build-validated (environment lacks .NET 11 SDK). Human review is needed.

Root cause

On tvOS Mono, exceptions thrown during async iterator execution in JsonSerializer.SerializeAsyncEnumerable are wrapped in a System.Reflection.TargetInvocationException. The tests use Assert.ThrowsAsync<InvalidOperationException> which fails when the expected exception is wrapped.

Failing log line:

Expected: typeof(System.InvalidOperationException)
Actual:   typeof(System.Reflection.TargetInvocationException)

This is a known behavioral difference in Mono's async iterator exception propagation. The InvalidOperationException IS correctly thrown by the serializer, but Mono wraps it during the async pipeline unwinding.

Fix

Replace Assert.ThrowsAsync<InvalidOperationException> with:

Exception ex = await Assert.ThrowsAnyAsync<Exception>(...);
if (ex is TargetInvocationException { InnerException: { } inner })
    ex = inner;
Assert.IsType<InvalidOperationException>(ex);

This correctly handles both:

  • CoreCLR: gets InvalidOperationException directly — assertion passes
  • Mono/tvOS: gets TargetInvocationException wrapping InvalidOperationException — unwraps and passes

Remove the [ActiveIssue] annotations since the fix addresses the root cause.

What is unverified / help needed

  • Build not validated: Environment has .NET 8/9 SDKs; the project targets .NET 11 preview.
  • Mono runtime bug: The real fix should be in Mono's async iterator exception propagation. This test change is a workaround that accepts Mono's behavior. Is that acceptable, or should the Mono runtime be fixed instead?
  • Other tests: There may be other tests in System.Text.Json that assert specific exception types from async operations and could have the same issue on Mono.

Suggested reviewers / area contacts

  • @eiriktsarpalis (area-System.Text.Json owner)
  • @simonrozsival (Apple mobile / Mono contributor)

Validation

  • Command: dotnet build src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj
  • Result: not run because environment lacks .NET 11 SDK

Evidence


Filed by ci-failure-fix, which attempts validated fixes for [ci-scan] Known Build Errors and otherwise loops in owners. Comment here or on the workflow file to suggest changes; ci-failure-scan-feedback reads in-scope feedback daily and opens (or updates) a PR with prompt edits.

Note

🔒 Integrity filter blocked 2 items

The following items were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by CI Outer-Loop Failure Fixer · ● 60.4M ·

On Mono/tvOS, async iterator exceptions propagated through
JsonSerializer.SerializeAsyncEnumerable are wrapped in a
TargetInvocationException. The tests previously used
Assert.ThrowsAsync<InvalidOperationException> which fails when the
exception is wrapped.

Replace with Assert.ThrowsAnyAsync<Exception> followed by explicit
unwrapping of TargetInvocationException, then assert the inner exception
is InvalidOperationException. This works correctly on both CoreCLR
(direct exception) and Mono (wrapped exception).

Remove the [ActiveIssue] annotations that disabled these tests on Apple
Mobile Mono since the fix addresses the behavioral difference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-ExceptionHandling-coreclr only use for closed issues label Jun 20, 2026
@jkotas jkotas added area-System.Text.Json and removed area-ExceptionHandling-coreclr only use for closed issues labels Jun 20, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant