dotnet / dotnet/sdk

[Preview 6 regression] `GenerateStaticWebAssetEndpointsManifest` throws `Sequence contains more than one element` when a MAUI Blazor Hybrid project references a Razor class library and the BlazorWebView package

Open
#54,779 0 comments 0 reactions 1 assignee Claimed by @javiercn View on GitHub
Area-AspNetCore untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

## Summary

In SDK `11.0.100-preview.6.26313.102`, building or publishing a .NET MAUI app that uses BlazorWebView and references a Razor Class Library fails on **multiple TFMs** (Windows AND Apple) with:

```
error : InvalidOperationException: Sequence contains more than one element
at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAssetEndpointsManifest
.ComputeManifestAssets(IEnumerable`1 assets, String kind)+MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateStaticWebAssetEndpointsManifest.Execute()
```

The same project builds and publishes cleanly on SDK `11.0.100-preview.5.26256.105`.

## Environment

| | |
|---|---|
| Failing SDK | `11.0.100-preview.6.26313.102` |
| Last good SDK | `11.0.100-preview.5.26256.105` |
| OS | Reproduces on both Windows and macOS CI hosted images |
| TFMs affected | `net11.0-windows10.0.19041.0`, `net11.0-windows10.0.20348.0`, `net11.0-maccatalyst`, `net11.0-ios` (any TFM where the BlazorWebView package targets are imported) |
| Failing CI jobs (PR #35364, build 1463118) | `Build Windows (Debug)`, `Build Windows (Release)`, `Build macOS (Release)`, `Samples windows` (integration test) |
| Project SDK | `Microsoft.NET.Sdk.Razor` |
| Target | `GenerateStaticWebAssetsPublishManifest` |
| Task | `GenerateStaticWebAssetEndpointsManifest` |
| Targets file | `.dotnet\sdk\11.0.100-preview.6.26313.102\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Publish.targets(55,5)` |

## Repro shape

A MAUI Hybrid app csproj (``) that:

1. Has Razor components and a `wwwroot/` folder with at least one `Maui.Controls.Sample.lib.module.js` plus a `css/app.css`.
2. ProjectReferences a Razor Class Library (`MauiRazorClassLibrarySample.csproj`) that also has `wwwroot/` content and scoped CSS.
3. ProjectReferences the BlazorWebView package (`Microsoft.AspNetCore.Components.WebView.Maui`) — preview.6 SDK assemblies for that package include a `_framework/blazor.modules.json` static web asset.

The full failing project is publicly available: [`src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj`](https://github.com/dotnet/maui/blob/net11.0/src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj) on the [.NET MAUI net11.0 branch](https://github.com/dotnet/maui/tree/net11.0).

## Root cause (from inspecting the binlog)

Three distinct `StaticWebAssetEndpoint` items collide on the same `Route='_framework/blazor.modules.json'`:

| # | Source kind | AssetFile (paths abbreviated) |
|---|---|---|
| 1 | Package (`All`) | `.packages\microsoft.aspnetcore.components.webview\11.0.0-preview.6.26313.102\staticwebassets\blazor.modules.json` |
| 2 | Build | `artifacts\obj\Maui.Controls.Sample\Release\net11.0-windows10.0.20348.0\win-x64\jsmodules\jsmodules.build.manifest.json` |
| 3 | Publish | `artifacts\obj\Maui.Controls.Sample\Release\net11.0-windows10.0.20348.0\win-x64\jsmodules\`**`jsmodules.publish.manifest.json`** |

Asset #3 (note the `.publish.` segment in the path) appears to be **new in preview.6** — preview.5 only produced `jsmodules.build.manifest.json`.

Looking at the failing code in [`src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsManifest.cs`](https://github.com/dotnet/sdk/blob/main/src/StaticWebAssetsSdk/Tasks/GenerateStaticWebAssetEndpointsManifest.cs#L206-L208):

```csharp
foreach (var group in assetsByTargetPath)
{
var asset = StaticWebAsset.ChooseNearestAssetKind(group, kind).SingleOrDefault(); // 💥 throws here
...
}
```

`ChooseNearestAssetKind(group, "Publish")` is returning >1 asset for the `_framework/blazor.modules.json` group, and `SingleOrDefault()` rejects it. The same pattern repeats for several `_content/MauiRazorClassLibrarySample/*` routes where the raw asset, the `.gz` compressed asset, and the `.br` publish-compressed asset collide under the same target path.

## Likely culprit

The behavior change in preview.6 is consistent with [#54353 — *Add support for materializing framework static web assets at project-to-project reference boundaries*](https://github.com/dotnet/sdk/pull/54353) (merged 2026-05-18). That PR changes how framework assets from package references flow across P2P boundaries, which is exactly the boundary being crossed in this scenario (Razor app → Razor class library → BlazorWebView package).

I haven't bisected to confirm — happy to do so if useful.

## Reproduction

The simplest public repro is to run `dotnet build` on a checkout of the [`.NET MAUI net11.0` branch](https://github.com/dotnet/maui/tree/net11.0) with SDK `11.0.100-preview.6.26313.102`. The `Build Windows` jobs of any maui-pr build on dotnet/maui PR [#35364](https://github.com/dotnet/maui/pull/35364) (which bumps SDK from preview.5 → preview.6) fail with this exception; the corresponding stage on the `net11.0` branch (still on preview.5) is green.

Reference failing build: [Azure DevOps 1463118](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1463118), job `Build Windows (Release)`. Binlog is from that build; happy to attach (or grab from the AzDO `Windows_NT_Build Windows (Release)_Attempt1` artifact).

## Expected behavior

The Publish manifest generation should disambiguate `Build`-kind, `Publish`-kind, and `All`-kind assets that map to the same target route, producing exactly one chosen asset per route per manifest kind — not throwing.

## Workaround on consumer side?

Not aware of a clean opt-out. Removing the `MauiRazorClassLibrarySample` ProjectReference avoids the failure but is not a real solution. Suggestions welcome.

## Related prior art

- [#50183](https://github.com/dotnet/sdk/issues/50183) — same `SingleOrDefault` exception in the sibling `GenerateStaticWebAssetsDevelopmentManifest` class; root cause was also two assets collapsing to the same target path.
- [#52281](https://github.com/dotnet/sdk/pull/52281) — `[StaticWebAssets] Fix duplicate asset detection in GroupAssetsByTargetPath` (Dec 2025).
- [#53305](https://github.com/dotnet/sdk/pull/53305) — `Handle duplicate static web asset identities gracefully` (Mar 2026).
- [#54353](https://github.com/dotnet/sdk/pull/54353) — likely culprit; introduces P2P framework asset materialization.

cc @javiercn @captainsafia (recent owners of this code)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.