Skip to content

[blazor] Fix Web Worker initialization on CoreCLR - #70504

Merged
maraf merged 2 commits into
mainfrom
maraf-fix-web-worker-coreclr-exports
Nov 12, 2026
Merged

maraf merged 2 commits into
mainfrom
maraf-fix-web-worker-coreclr-exports

Conversation

@maraf

@maraf maraf commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

[blazor] Fix Web Worker initialization on CoreCLR

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Fix Web Worker initialization on CoreCLR.

Description

CoreCLR throws when getAssemblyExports is called for a host assembly with no [JSExport] methods. Bind only the configured worker assembly and re-enable the four WebWorkerTemplateE2ETest cases. WebWorkerClient.CreateAsync supplies the worker library assembly name by default.

This intentionally stops automatically including host-assembly exports and removes the fallback to the main assembly when no assembly name is supplied.

Validation

  • A standalone CoreCLR browser repro using .NET 11 RC3 failed with the original worker because the host had no exports; it passed initialization, invocation, error handling and disposal with the fix, both built and published. Commands: dotnet build -v q, dotnet run --no-build --urls http://127.0.0.1:5199, node /private/tmp/wwprobe/probe.mjs http://127.0.0.1:5199/webworker-test, dotnet publish -o /private/tmp/wwrepro/pub -v q, cd /private/tmp/wwrepro/pub/wwwroot && python3 -m http.server 5198 --bind 127.0.0.1, and node probe.mjs http://127.0.0.1:5198/ webworker-test. This browser run was before removal of the fallback, which was not used because the worker assembly name was supplied.
  • node --input-type=module with a JavaScript VM probe of the final worker and a simulated runtime: passed. The baseline attempted to bind the host and failed; the final worker bound only the supplied worker assembly, invoked its export, and propagated errors.
  • source activate.sh && dotnet test src/ProjectTemplates/test/Templates.Blazor.Tests/Templates.Blazor.Tests.csproj --no-build --no-restore --filter 'FullyQualifiedName~WebWorkerTemplateE2ETest': blocked because the test assembly and full local package graph have not been built. The four re-enabled repository tests were not run.

Fixes: #70502 (follow-up to #70481).

Note

This PR description was generated with the assistance of GitHub Copilot.

maraf and others added 2 commits November 11, 2026 13:22
Bind only the configured worker assembly's [JSExport] methods instead of
also binding the host's main assembly. On CoreCLR, getAssemblyExports throws
when the assembly has no generated JS export initializer, which is typical
for the host app. Re-enable the WebWorkerTemplateE2ETest cases.

Co-authored-by: Copilot App <[email protected]>
@maraf
maraf requested a review from a team as a code owner November 11, 2026 13:33
Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:33
@maraf maraf added the area-blazor Includes: Blazor, Razor Components label Nov 11, 2026
@maraf maraf self-assigned this Nov 11, 2026
@github-actions github-actions Bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Nov 11, 2026

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.

🟢 Approval recommended

No active review issues are reported for the worker-export lookup change, though the re-enabled browser tests were not run because build prerequisites were missing.

No open issues 🎉

What changed in this PR

Fixes Blazor Web Worker initialization on CoreCLR by avoiding export lookup on a host assembly that may have no [JSExport] methods. This follows the template-test infrastructure’s move away from Mono.

Changes:

  • Loads exports only from the configured worker assembly, removing automatic host exports and the main-assembly fallback.
  • Re-enables four browser tests covering invocation, error handling, disposal, and invocation after publishing.

The re-enabled repository tests were not run because the required test assembly and local package graph had not been built.

File Description
src/​ProjectTemplates/​Web.ProjectTemplates/​content/​BlazorWebWorker-CSharp/​wwwroot/​dotnet-web-worker.js Restricts export lookup to the configured worker assembly.
src/​ProjectTemplates/​test/​Templates.Blazor.Tests/​WebWorkerTemplateE2ETest.cs Removes CoreCLR-related skips from four browser tests.

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot 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.

Source-only review of frozen head 75c8f6c791b539245d98734a95ab2f982e9c06b0.

One P2 candidate is published inline with unresolved confidence: the diff removes main-assembly export merging, but the frozen bundle does not contain the target-version-bound runtime contract/source needed to prove the resulting getConfig()/getAssemblyExports() behavior. No verified defect is asserted.

  • Guide completion: docs/CrossCuttingGuidance.md completed its in-scope cross-cutting checks. Runtime, CI, browser, and sample execution were excluded by the source-only policy; security assessment was explicitly out of scope.
  • Existing feedback: Frozen feedback contained no equivalent supported finding to deduplicate. This is a neutral coverage statement, not an endorsement of prior reviews.
  • Unresolved: Exact .NET runtime export-discovery semantics for distinct host and worker assemblies.
  • Uncovered: No specialist guide covered Web Worker/runtime template semantics beyond the cross-cutting review.
  • Test boundary: Tests and target code were not executed. The re-enabled E2E tests were assessed from source and cover WorkerLib exports, not a distinct host-assembly export.
  • Provenance: PR 70504; merge base/base tip 50f5c66e0b4522be2848078a14f418fb74fe59dc; trusted guidance commit 50f5c66e0b4522be2848078a14f418fb74fe59dc. Evidence was limited to frozen tracked Git bytes; symlinks, submodules, and LFS targets are inert. Feedback posted after bundle preparation was not observable.

Generated by ASP.NET Core Pull Request Review for #70504 · copilot · gpt56 · 124.6 AIC · ⌖ 22 AIC · ⊞ 18.8K
Comment /review to run again

workerExports = { ...workerExports, ...await getAssemblyExports(assemblyName) };
}
const { getAssemblyExports } = await dotnet.create();
workerExports = { ...await getAssemblyExports(assemblyName) };

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.

P2 · confidence: unresolved

[UNRESOLVED] Host-assembly [JSExport] methods may no longer be callable when WebWorkerClient is supplied by a separate worker library.

Why unresolved: The frozen repository source shows that the merge base loaded and merged mainAssemblyName plus the requested assembly, while this line loads only the requested assembly. However, the bundle does not include a target-version-bound runtime contract, runtime source, or immutable validation artifact proving the exact getConfig()/getAssemblyExports() semantics needed to establish the old/new observable behavior.

Minimal repro: In a host whose main assembly differs from WorkerLib, define a host [JSExport], reference WorkerLib, call WebWorkerClient.CreateAsync(JSRuntime) without an assembly name, then invoke the host export's fully qualified path.

What may go wrong: If the runtime APIs behave as assumed by the previous implementation, the host export is absent and invocation returns Method not found.

Possible fix: Preserve main-assembly exports when a distinct worker assembly is selected, while avoiding export lookup for assemblies that cannot provide exports; otherwise add a binding contract and coverage for the intentional single-assembly behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This function is intended to be called through the template's C# WebWorkerClient.CreateAsync wrapper. That wrapper always resolves assemblyName—defaulting it to the assembly containing WebWorkerClient—before calling the JavaScript create function. The JavaScript module is an implementation detail; the template doesn't call it directly.

Auto-replied by the GitHub Copilot app

@PureWeen

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

Informational - [UNRESOLVED], not blocking (P3): At src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWebWorker-CSharp/wwwroot/dotnet-web-worker.js:8, direct JavaScript use of the client module's create(timeout) without options now passes null to getAssemblyExports instead of selecting the main assembly. The normal C# WebWorkerClient.CreateAsync path supplies an assembly name, and the PR description explicitly says fallback removal is intentional. The panel did not establish the target runtime's behavior for getAssemblyExports(null) or demonstrate a failure; the verifier returned DOWNGRADE/external.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

The existing host-assembly-export concern in discussion 4539519917 was not duplicated. This was a source review, not runtime validation.

Human-directed and GitHub Copilot-generated.

@maraf
maraf merged commit fd8f5ac into main Nov 12, 2026
45 checks passed
@maraf
maraf deleted the maraf-fix-web-worker-coreclr-exports branch November 12, 2026 09:02
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:02 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:03 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:04 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:06 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:06 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 12, 2026 09:07 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 25%

No docs needed. This is a bug fix to the Web Worker template initialization, and the existing documentation already describes the resulting behavior.

Documentation surfaces considered

  • Conceptual article: Not required — The template worker script now binds only the supplied worker assembly, which matches the documented default of the worker project's assembly. The existing article is already accurate. The only other changed file is an E2E test.
  • Migration guidance: Not required — The fix makes the template work on CoreCLR. Nothing needs to change for users upgrading.
  • Breaking change: Not required — Host-assembly exports are no longer bound automatically. This is a follow-up to the template added in Remove Mono browser runtime usage from build and test infrastructure #70481 in the same release, so there's no concrete compatibility impact on shipped behavior. A maintainer could confirm this.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 75c8f6c7 Deployed Nov 12, 2026 by maraf via conclusion #307
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-enable Web Worker template tests after runtime JSExport fix flows

5 participants