maui icon indicating copy to clipboard operation
maui copied to clipboard

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

Open jhovelnu opened this issue 6 months ago • 4 comments

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

Image

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

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


jhovelnu avatar Jun 12 '25 17:06 jhovelnu

This issue has been verified in Visual Studio 17.14.5 Preview 1.0 with MAUI versions (9.0.80 ,9.0.71, 9.0.70, 9.0.60, 9.0.50, 9.0.0). It can be reproduced on the Android platform.

Image

NafeelaNazhir avatar Jun 13 '25 06:06 NafeelaNazhir

I've received the same error on a NET MAUI app using (NET 10 Preview 5) on a Windows 11. However I've also received the message in a Blazor WASM and Blazor Server app (NET 9) so I don't think the problem is just MAUI, might be something related to VisualStudio or even Blazor

JaimeBernar avatar Jun 16 '25 08:06 JaimeBernar

@JaimeBernar thanks for contacting us.

Can you try with the 9.0.301 SDK? There was an issue on the 9.0.300 SDK related to duplicate items that might be the root cause here.

Alternatively, could you include a binlog so that we can take a look?

javiercn avatar Jun 17 '25 13:06 javiercn

@JaimeBernar @javiercn

Hi.

Is there anything I can do to help with the tests you are working on?

jhovelnu avatar Jun 24 '25 13:06 jhovelnu

@jhovelnu can you try with the 9.0.301 SDK?

I did try with it myself and was not able to reproduce the issue. Alternatively, providing a binlog with dotnet build /bl that reproduces the issue will help.

javiercn avatar Jun 24 '25 13:06 javiercn

Hello @javiercn

I tested using the .NET SDK 9.0.301, and the issue still persists.

https://github.com/jhovelnu/MauiAppBlazor

error MSB4018: The "FilterStaticWebAssetEndpoints" task failed unexpectedly. 3>C:\Program Files\dotnet\sdk\9.0.301\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.

msbuild.zip

jhovelnu avatar Jun 24 '25 13:06 jhovelnu

@jhovelnu your binlog doesn't show the error. It says build succeeded

javiercn avatar Jun 24 '25 17:06 javiercn

@javiercn Yes, the dotnet build command doesn't show any errors, but when building or launching the app from Visual Studio, the error appears in the build output.

Image

Image

jhovelnu avatar Jun 24 '25 23:06 jhovelnu

@jhovelnu can you follow

https://github.com/dotnet/project-system-tools?tab=readme-ov-file#getting-higher-fidelity-logs-from-vs-vs2022-onwards

to capture the binlog from the failing build?

javiercn avatar Jun 25 '25 09:06 javiercn

@javiercn here are the logs

LogVisualStudio.zip

jhovelnu avatar Jun 25 '25 13:06 jhovelnu

I get similar issues when I try to move a Maui/Blazor hybrid project to a new folder even after doing both a clean and a rebuild. There are generated files hanging around somewhere that contain conflicting information based on the new folder structure

dragnldy avatar Jun 30 '25 17:06 dragnldy

Hi,

Is there any workaround or fix to this issue?, This error still occurs.

Elinares-82 avatar Aug 28 '25 23:08 Elinares-82

pls this still persists! in .net 10 / 9 dotnet publish can build apk/ipa fine but visual studio 2022 / 2026 fails to gather all static web assets

AiTlbx avatar Nov 12 '25 20:11 AiTlbx