Maui Blazor Compilation error System.ArgumentException: An item with the same key has already been added.
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:
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.
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
- Create a Maui Blazor App
- Add a new project to put the MainPage
- Move the wwwroot folder and components from the main maui project to the new project
- 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
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.
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 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?
@JaimeBernar @javiercn
Hi.
Is there anything I can do to help with the tests you are working on?
@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.
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.
@jhovelnu your binlog doesn't show the error. It says build succeeded
@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.
@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?
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
Hi,
Is there any workaround or fix to this issue?, This error still occurs.
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