Repository navigation
[ci-fix-net11] Guard Blazor sample JS interop calls - #36888
Conversation
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
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36888Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36888" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
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 rethrowInvalidOperationExceptionwith clearer operation context. - Ignore
JSDisconnectedExceptionduring 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
| if (moduleTask.IsValueCreated) | ||
| { | ||
| var module = await moduleTask.Value; | ||
| await module.DisposeAsync(); | ||
| try | ||
| { |
| if (moduleTask.IsValueCreated) | ||
| { | ||
| var module = await moduleTask.Value; | ||
| await module.DisposeAsync(); | ||
| try | ||
| { |
|
/azp run maui-pr-uitests, maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
kubaflo
left a comment
There was a problem hiding this comment.
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:
JSDisconnectedExceptiongenuinely fires in BlazorWebView (not a Blazor‑Server‑only concept):WebViewJSRuntime.BeginInvokeJSthrows it oncePageContext.DisposeAsync→MarkAsDisconnected()runs during WebView teardown. So thecatch (JSDisconnectedException)aroundmodule.DisposeAsync()is correct and relevant — verifiedJSDisconnectedException : ExceptionandJSException : Exceptionare siblings, so thecatch (JSException)on import/Promptdeliberately does not absorb disconnects; the disconnect case is handled at disposal. (FrameworkJSObjectReference.DisposeAsyncalready swallows it internally too, so the guard is belt‑and‑suspenders — harmless.)- The
Lazy<Task<IJSObjectReference>>refactor is behavior‑preserving:new(async () => await InvokeAsync<…>(…))infersFunc<Task<…>>, drops.AsTask()in favor of async re‑wrapping, runs the factory once, awaits theValueTaskonce. No double‑wrap, no regression. - Rethrowing as
InvalidOperationExceptionpreservesInnerException; both projects are non‑packable samples, so no consumer/test depends on the originalJSExceptionsurfacing. Net improvement to error reporting. - Both files consistent (
_content/<AssemblyName>/…paths correct); only legitimate divergence isWebViewAppShared's extraUpdateControlDiv, 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.
<!-- 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
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.cssrc/BlazorWebView/samples/MauiRazorClassLibrarySample/ExampleJsInterop.csThe updated .NET 11 Preview 7 SDK flowing through #36838 enables BL0016 analysis for these JavaScript interop calls. This focused change prepares
net11.0for 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
JSExceptionand rethrowInvalidOperationExceptionwith operation-specific context. Module disposal catches onlyJSDisconnectedException, because a disconnected JavaScript context no longer requires disposal; other disposal failures continue to propagate.CI evidence
ExampleJsInteropcopies after the Preview 7 dependency update.WebViewAppSharedsource 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 errorsdotnet build src/BlazorWebView/samples/WebViewAppShared/WebViewAppShared.csproj -f net11.0 -c Release— passed, 0 warnings and 0 errorsdotnet build src/BlazorWebView/samples/MauiRazorClassLibrarySample/MauiRazorClassLibrarySample.csproj -f net11.0 -c Debug— passed, 0 warnings and 0 errorsdotnet build src/BlazorWebView/samples/MauiRazorClassLibrarySample/MauiRazorClassLibrarySample.csproj -f net11.0 -c Release— passed, 0 warnings and 0 errorssrc/BlazorWebView/samples/**: exactly twoExampleJsInteropimplementations and seven relevantIJSRuntime/IJSObjectReferenceinvocation or disposal call sites; all operational calls are guarded and disconnection is ignored only during disposal.git diff --checkpassed.