Skip to content

[ci-fix-net11] Guard Blazor sample JS interop calls - #36888

Merged
kubaflo merged 1 commit into
net11.0from
pureween-fix-net11-js-interop
Jul 28, 2026
Merged

kubaflo merged 1 commit into
net11.0from
pureween-fix-net11-js-interop

Conversation

@PureWeen

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Summary

Extracts both validated BL0016 sample fixes from dependency PR #36838 onto net11.0:

  • src/BlazorWebView/samples/WebViewAppShared/ExampleJsInterop.cs
  • src/BlazorWebView/samples/MauiRazorClassLibrarySample/ExampleJsInterop.cs

The updated .NET 11 Preview 7 SDK flowing through #36838 enables BL0016 analysis for these JavaScript interop calls. This focused change prepares net11.0 for that flowed SDK; it does not assert that the branch's older SDK currently fails these builds.

Exception semantics

Operational module import, prompt, and DOM update calls catch JSException and rethrow InvalidOperationException with operation-specific context. Module disposal catches only JSDisconnectedException, because a disconnected JavaScript context no longer requires disposal; other disposal failures continue to propagate.

CI evidence

  • maui-pr build 1528734 surfaced BL0016 diagnostics in both ExampleJsInterop copies after the Preview 7 dependency update.
  • maui-pr build 1529843, after the WebViewAppShared source fix, had no remaining diagnostics for that copy and still identified the Razor class library copy, motivating the second validated fix.

Validation

  • dotnet build src/BlazorWebView/samples/WebViewAppShared/WebViewAppShared.csproj -f net11.0 -c Debug — passed, 0 warnings and 0 errors
  • dotnet build src/BlazorWebView/samples/WebViewAppShared/WebViewAppShared.csproj -f net11.0 -c Release — passed, 0 warnings and 0 errors
  • dotnet build src/BlazorWebView/samples/MauiRazorClassLibrarySample/MauiRazorClassLibrarySample.csproj -f net11.0 -c Debug — passed, 0 warnings and 0 errors
  • dotnet build src/BlazorWebView/samples/MauiRazorClassLibrarySample/MauiRazorClassLibrarySample.csproj -f net11.0 -c Release — passed, 0 warnings and 0 errors
  • Searched src/BlazorWebView/samples/**: exactly two ExampleJsInterop implementations and seven relevant IJSRuntime/IJSObjectReference invocation or disposal call sites; all operational calls are guarded and disconnection is ignored only during disposal.
  • git diff --check passed.

Wrap operational JavaScript interop failures with contextual exceptions and ignore JS disconnection only while disposing loaded modules.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c6ae0385-a806-4d6c-9725-dc102062c5c4
Copilot AI review requested due to automatic review settings July 28, 2026 17:56
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 17:56 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36888

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36888"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 17:57 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 17:59 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 18:01 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 18:02 — with GitHub Actions Inactive
@github-actions github-actions Bot added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Jul 28, 2026
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool July 28, 2026 18:02 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the BL0016-related JavaScript interop guarding fixes into the two BlazorWebView sample projects on net11.0, so the samples remain warning-free when the updated .NET 11 Preview 7 SDK analyzers are enabled.

Changes:

  • Wrap JS module import and JS interop calls in try/catch (JSException) and rethrow InvalidOperationException with clearer operation context.
  • Ignore JSDisconnectedException during module disposal (best-effort cleanup when the JS runtime is gone).
Show a summary per file
File Description
src/BlazorWebView/samples/WebViewAppShared/ExampleJsInterop.cs Adds guarded JSImport/module calls and best-effort dispose handling for disconnected JS runtime.
src/BlazorWebView/samples/MauiRazorClassLibrarySample/ExampleJsInterop.cs Mirrors the same guarded JSImport/module calls and dispose behavior in the Razor class library sample.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines 62 to +66
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
try
{
Comment on lines 49 to +53
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
try
{
@PureWeen

Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests, maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 — adversarial 4-model review (Claude Opus 4.8 + GPT‑5.5 + Gemini 3.1 Pro + GPT‑5.6 Sol), findings independently verified against ASP.NET Core framework source.

✅ LGTM. This is a correct, low-risk sample hardening. I verified the load-bearing facts against the actual framework, not assumptions:

  • JSDisconnectedException genuinely fires in BlazorWebView (not a Blazor‑Server‑only concept): WebViewJSRuntime.BeginInvokeJS throws it once PageContext.DisposeAsync → MarkAsDisconnected() runs during WebView teardown. So the catch (JSDisconnectedException) around module.DisposeAsync() is correct and relevant — verified JSDisconnectedException : Exception and JSException : Exception are siblings, so the catch (JSException) on import/Prompt deliberately does not absorb disconnects; the disconnect case is handled at disposal. (Framework JSObjectReference.DisposeAsync already swallows it internally too, so the guard is belt‑and‑suspenders — harmless.)
  • The Lazy<Task<IJSObjectReference>> refactor is behavior‑preserving: new(async () => await InvokeAsync<…>(…)) infers Func<Task<…>>, drops .AsTask() in favor of async re‑wrapping, runs the factory once, awaits the ValueTask once. No double‑wrap, no regression.
  • Rethrowing as InvalidOperationException preserves InnerException; both projects are non‑packable samples, so no consumer/test depends on the original JSException surfacing. Net improvement to error reporting.
  • Both files consistent (_content/<AssemblyName>/… paths correct); only legitimate divergence is WebViewAppShared's extra UpdateControlDiv, also correctly guarded.

Minor, non‑blocking (noted for completeness, not a change request): in DisposeAsync, var module = await moduleTask.Value; sits outside the try, so if Prompt was called and the import previously faulted, disposal re‑throws (an InvalidOperationException, or a raw JSDisconnectedException only in the narrow disconnect‑at‑first‑import‑then‑dispose edge). This line placement is pre‑existing (git show HEAD~1 shows the same structure) and doesn't affect the analyzer fix — safe to leave, or optionally move the await inside the guard in a follow‑up.

CI note (why this is a COMMENT, not an approval)

maui-pr went red, but I verified the failure is pre‑existing net11 branch flakiness, not this PR: the red legs are all‑platform maui-pr-devicetests (Android/iOS/MacCatalyst/Windows, CoreCLR + Mono), Windows Helix Unit Tests, and Integration Tests Blazor/Samples — none of which build or reference these two BlazorWebView sample .cs files. The same Integration‑Blazor/Samples legs are failing on #36885 (a net11 PR that doesn't touch these files), and the Blazor failure is a runtime "Test suite had 1 failure(s)", not a sample build error. So the code is LGTM and CI‑red is unrelated — but since I don't auto‑approve on a red maui-pr, I'm leaving this as a comment for your usual pre‑existing‑flakiness merge call rather than a formal approval.

Reviewed at head 286f8206c36. Opus/GPT/Sol → READY (GPT built both projects clean, 0 warnings); Gemini's lone Medium (the await‑outside‑try) is real but pre‑existing and narrow — down‑weighted after I confirmed the original had identical placement.

🤖 AI-assisted adversarial review (Opus 4.8 + GPT‑5.5 + Gemini 3.1 Pro + Sol; orchestrator independently verified the JSInterop exception hierarchy and throw sites against dotnet/aspnetcore source). Not a maintainer approval.

@kubaflo
kubaflo merged commit cbb408f into net11.0 Jul 28, 2026
119 of 149 checks passed
@kubaflo
kubaflo deleted the pureween-fix-net11-js-interop branch July 28, 2026 20:34
@github-actions github-actions Bot added this to the .NET 11.0-preview7 milestone Jul 28, 2026
kubaflo pushed a commit that referenced this pull request Jul 30, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Refreshes `net11.0` from the latest builds on the `.NET 11.0.1xx SDK`
channel and fixes the official workload and sample-build failures
exposed by the RC1 transition.

| Source | BAR build | Build/version | Commit |
|---|---:|---|---|
| `dotnet/dotnet` | 324908 | `20260729.2` / SDK
`11.0.100-rc.1.26379.102` / Arcade `11.0.0-beta.26379.102` |
`813f634ceb016018f5acc9bd3c2b16e17dff4686` |
| `dotnet/macios` | 324699 | `20260728.2` / Apple
`26.5.11992-net11-rc.1` | `17d5ebd7632ca2960ab6e3d4bdb68697d24bc2ba` |
| `dotnet/android` | 324914 | `11.0.0-preview.7.26379.1+azdo.14802945` /
Android `37.0.0-ci.main.2160` |
`444db99f7b362334b2785498c57064a4c66a7165` |

The dependency refresh updates `eng/Version.Details.xml`,
`eng/Versions.props`, and `global.json`, while preserving the macOS
dependency feed update in `NuGet.config`. The macOS net10 coherent
dependencies remain mapped to BAR 324587, and the previous Android
manifest remains mapped to BAR 315081.

The branch also merges the current `net11.0` tip so it includes the
already-merged `ExampleJsInterop` BL0016 fixes from #36888.

### RC1 build fixes

- Advances `Microsoft.DotNet.Arcade.Sdk` and related VMR dependencies to
`11.0.0-beta.26379.102`, replacing the unavailable
`11.0.0-beta.26365.101` requested by failing official build 3034332.
- Temporarily pins the Android and Apple workload manifest package IDs
to `11.0.100-preview.7`. Their latest component builds contain RC1
product versions but still publish Preview 7 manifest package IDs; using
the VMR-derived RC1 IDs fails restore with `NU1101`.
- Removes MAUI's duplicate explicit `.cab` `FileExtensionSignInfo`;
Arcade already signs `.cab` files with `Microsoft400`.
- Restores `<MicrosoftWixVersion>6.0.3-dotnet.4</MicrosoftWixVersion>`
so all five WiX 6 package references have a version.
- Guards the Controls sample's `confirm`, `prompt`, and `alert`
JavaScript interop calls with `JSException` handling. The RC1 BL0016
analyzer rejects these calls when they are outside a `try`/`catch`;
exceptions are rethrown as operation-specific
`InvalidOperationException`s rather than suppressed or swallowed.

The signing and WiX changes reproduce the final implementation from
merged PR #36879 (merge commit
`67c53f3a438adf50bc1023321f33d7bc2e5bf6f9`) without merging or
cherry-picking the release-branch commit.

### Validation

- XML and JSON parsing; `git diff --check`
- Exact BAR asset/version/SHA mapping for all refreshed dependencies and
coherent prior pins
- `darc verify` (only unchanged baseline Tizen/XUnit duplicate aliases
and XHarness casing/version findings remain)
- Workload bootstrap/restore and targeted MSBuild preparation using
Arcade `11.0.0-beta.26379.102`
- WiX restore resolves all five references to `6.0.3-dotnet.4`
- No explicit `.cab` signing entry remains in `eng/Signing.props`
- `Maui.Controls.Sample.csproj -f net11.0 -c Debug` under SDK
`11.0.100-rc.1.26379.102` — passed with 0 warnings/errors
- `Maui.Controls.Sample.csproj -f net11.0 -c Release` under SDK
`11.0.100-rc.1.26379.102` — passed with 0 warnings/errors

### Issues Fixed

No linked GitHub issue. Fixes the `net11.0` official pipeline dependency
provisioning, workload restore, signing, WiX restore, and RC1 BL0016
sample-build failures.

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d483d48e-8fc4-43ba-a37f-ac8d32c45fd5
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 28, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 286f8206 Deployed Jul 28, 2026 by PureWeen via conclusion #1006
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-blazor Blazor Hybrid / Desktop, BlazorWebView

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants