dotnet / dotnet/maui

Maui Blazor Compilation error System.ArgumentException: An item with the same key has already been added.

Open
#29,969 14 comments 0 reactions 0 assignees View on GitHub
area-blazor platform/android s/needs-attention s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I am building a hybrid Blazor application, but I'm encountering an error during the build process when trying to launch the app.

I created a blazor project with the template:

![Image](https://github.com/user-attachments/assets/6fcca977-5151-482c-8176-272aa9db6864)

![Image](https://github.com/user-attachments/assets/4a4cb658-8fa7-4cb2-80c5-ab7f18d765c1)

In my solution, there is an additional project that contains the Pages. For this test I have created the MauiAppBlazor.Controls to simulate the scenary.

![Image](https://github.com/user-attachments/assets/b2536cbd-7171-44b4-8db4-9882e4a4c3cd)

Finally I am getting this error in visual studio when I try to launch the app: System.ArgumentException: An item with the same key has already been added.

### Steps to Reproduce

1. Create a Maui Blazor App
2. Add a new project to put the MainPage
3. Move the wwwroot folder and components from the main maui project to the new project
4. From MauiAppBlazor reference the new project to call the MainPage

When you try to compile or launch the app, you will get this error:

2>C:\Program Files\dotnet\sdk\9.0.204\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.ScopedCss.targets(397,3): error MSB4018: The "FilterStaticWebAssetEndpoints" task failed unexpectedly.
2>C:\Program Files\dotnet\sdk\9.0.204\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.ScopedCss.targets(397,3): error MSB4018: System.ArgumentException: An item with the same key has already been added.

### Link to public reproduction project repository

https://github.com/jhovelnu/MauiAppBlazor

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

_No response_

### Affected platforms

Android

### Affected platform versions

_No response_

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the linked MauiAppBlazor project, then inspect Microsoft.NET.Sdk.StaticWebAssets.targets around line 397 and the FilterStaticWebAssetEndpoints task. Done means the project compiles and launches without the duplicate-key ArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
build-system, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.