Skip to content

[StaticWebAssets] Fix endpoints manifest crash when an All and a more specific asset share a target path (#54779) - #54930

Closed
PureWeen wants to merge 1 commit into
dotnet:mainfrom
PureWeen:fix-54779-swa-endpoints-manifest
Closed

PureWeen wants to merge 1 commit into
dotnet:mainfrom
PureWeen:fix-54779-swa-endpoints-manifest

Conversation

@PureWeen

Copy link
Copy Markdown
Member

Fixes #54779

Regression (Preview 6)

A MAUI Blazor Hybrid app that references a Razor class library and the Microsoft.AspNetCore.Components.WebView (BlazorWebView) package fails to build with:

GenerateStaticWebAssetEndpointsManifest ... Sequence contains more than one element

Root cause

Three static web assets map to the same target path _framework/blazor#[.{fingerprint}]?.modules.json:

  • an All asset coming from the BlazorWebView package,
  • an All project build JS-modules manifest, and
  • new in Preview 6, a Publish project publish JS-modules manifest.

StaticWebAsset.ChooseNearestAssetKind surfaced the "two All assets" ambiguity eagerly (it yielded both and breaked) before it ever reached the more specific Publish asset, so the consumer's SingleOrDefault() threw. GenerateStaticWebAssetEndpointsManifest itself is unchanged — the new publish manifest changed the input to it.

Fix

Defer the multi-All decision: track up to two All candidates and only surface them (so the caller can still error on a genuine ambiguity) when no more specific Build/Publish asset is present in the group. A more specific asset that appears after the All assets now correctly wins. This also fixes the identical latent path in GenerateStaticWebAssetsDevelopmentManifest — the only other caller of ChooseNearestAssetKind.

Testing

  • Added GeneratesPublishManifest_WhenAllAndPublishAssetsShareTargetPath_PrefersPublishAsset, which reconstructs the exact 3-asset group. It throws Sequence contains more than one element before the fix and passes after, producing a single endpoint sourced from the publish manifest.
  • Existing GenerateStaticWebAssetEndpointsManifestTest (5), GenerateStaticWebAssetsDevelopmentManifestTest (23), and GenerateStaticWebAssetsManifestTest (19) all still pass.

…re specific asset share a target path

Fixes dotnet#54779

A MAUI Blazor Hybrid app that references a Razor class library and the
Microsoft.AspNetCore.Components.WebView (BlazorWebView) package fails to
build in Preview 6 with:

    GenerateStaticWebAssetEndpointsManifest ... Sequence contains more than one element

Three assets map to the same target path
"_framework/blazor#[.{fingerprint}]?.modules.json":
 * an `All` asset from the BlazorWebView package,
 * an `All` project *build* JS modules manifest, and
 * (new in Preview 6) a `Publish` project *publish* JS modules manifest.

ChooseNearestAssetKind surfaced the "two `All` assets" ambiguity eagerly
(yielding both and breaking) before it reached the more specific `Publish`
asset, so SingleOrDefault() threw. The task itself is unchanged; the new
publish manifest changed the input.

Defer the multi-`All` decision: track up to two `All` candidates and only
surface them (so callers can still error on genuine ambiguity) when no more
specific Build/Publish asset exists in the group. A specific asset that
appears after the `All` assets now correctly wins. This also fixes the
identical latent path in GenerateStaticWebAssetsDevelopmentManifest, the only
other caller of ChooseNearestAssetKind.

Adds a regression test reproducing the exact asset group; it throws before
the fix and passes after.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant