dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.23k stars 9.95k forks source link

"An item with the same key has already been added." in Blazor Webasm #37825

Closed manuelelucchi closed 10 months ago

manuelelucchi commented 2 years ago

Describe the bug

In a Blazor Webasm Hosted Application (but launched as non hosted) I get the exception reported below. The exception (that can be seen from the browser console) gets raised twice sequentially. "Egea.Electron.Web.App", the key that raise the exception, is the main Razor component, the one added with builder.RootComponents.Add<App>("#app");. It gets explicitly added only once, and the error appeared out of nowhere today, while yesterday the project was doing fine. The only thing I can think of is that I have updated from VS2022 RC1 to RC2. The project is currently targeting .NET 5.

To Reproduce

I have no idea on how to reproduce, an app created from zero works fine and I can't show my project/is too complex to be shown

Exceptions (if any)

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: An item with the same key has already been added. Key: Egea.Electron.Web.App System.ArgumentException: An item with the same key has already been added. Key: Egea.Electron.Web.App at System.Collections.Generic.Dictionary2[[System.Type, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryInsert(Type key, String[] value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2[[System.Type, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(Type key, String[] value) at Microsoft.AspNetCore.Components.RouteTableFactory.Create(IEnumerable1 componentTypes) at Microsoft.AspNetCore.Components.RouteTableFactory.Create(IEnumerable1 assemblies) at Microsoft.AspNetCore.Components.Routing.Router.RefreshRouteTable() at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted) at Microsoft.AspNetCore.Components.Routing.Router.SetParametersAsync(ParameterView parameters)

Further technical details

dotnet --info Output ``` .NET SDK (che rispecchia un qualsiasi file global.json): Version: 6.0.100-rc.2.21505.57 Commit: ab39070116 Ambiente di runtime: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\ Host (useful for support): Version: 6.0.0-rc.2.21480.5 Commit: 6b11d64e7e .NET SDKs installed: 5.0.402 [C:\Program Files\dotnet\sdk] 6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download ```

Thank you in advance for your help, Manuele

javiercn commented 2 years ago

@manuelelucchi thanks for contacting us.

Unfortunately without a repro project we can't make progress on this issue. We would suggest you try and clean your bin,obj folders and perform a clean build and see if that helps.

ghost commented 2 years ago

Hi @manuelelucchi. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

manuelelucchi commented 2 years ago

Here I am again, I found the issue. A class was moved back to the main assembly and it was the class used to register (using typeof().Assembly) an additional assembly to the Router component, causing the assembly to be explored 2 times.

I think this should have a control that stops you from adding multiple time the same assembly/a more clear error about it

Thank you for your patience Manuele

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mkArtakMSFT commented 10 months ago

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.