Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet-sdk-9.0.100-preview.5.24281.15] Fail to build the app after retargeted to .NET 9.0 with error “System.ArgumentException: An item with the same key has already been added.” #56029

Closed
1 task done
Junjun-zhao opened this issue Jun 3, 2024 · 12 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@Junjun-zhao
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When retarget the 3rd party application to net9.0 with the latest .NET 9 build, it failed to build with error "The "DefineStaticWebAssetEndpoints" task failed unexpectedly. System.ArgumentException: An item with the same key has already been added.".

Application Name: NSK, Blazorise, OpenMu
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-preview.5.24281.15
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2069020
Github Link:
https://github.com/andysal/NSK
https://github.com/Megabit/Blazorise
https://github.com/MUnique/OpenMU

Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.301: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.4.24267.66: Pass
3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.5.24277.8: Fail
4). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.5.24281.15: Fail

Expected Behavior

build successfully.

Steps To Reproduce

Minimal Repro steps (Demo attached): BlazorAppDemo (1).zip

  1. Create a net7.0 blazor server project named BlazorApp1.
  2. Create another net7.0 blazor server project named BlazorApp2 in the same solution.
  3. BlazorApp1 add project reference with BlazorApp2.
  4. Retarget BlazorApp1 to net9.0.
  5. Build BlazorApp1.

Exceptions (if any)

Show error MSB4018:

The "DefineStaticWebAssetEndpoints" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
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.DefineStaticWebAssetEndpoints.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

.NET Version

dotnet-sdk-9.0.100-preview.5.24281.15

Anything else?

Dotnet Info:
.NET SDK:
 Version:           9.0.100-preview.5.24281.15
 Commit:            b6a8831c57
 Workload version:  9.0.100-manifests.6fd52e3d
 MSBuild version:   17.11.0-preview-24279-02+b963c24ef

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.5.24281.15\

Host:
  Version:      9.0.0-preview.5.24280.5
  Architecture: x64
  Commit:       de6897b3b7

.NET SDKs installed:
  9.0.100-preview.5.24281.15 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.5.24280.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.5.24280.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.5.24280.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jun 3, 2024
@javiercn
Copy link
Member

javiercn commented Jun 3, 2024

@Junjun-zhao thanks for contacting us.

What's happening here is that site.css and site.css in both projects have the same content, and that results in the file name we choose for compression ends up being the same.

@javiercn javiercn added the bug This issue describes a behavior which is not expected - a bug. label Jun 3, 2024
@javiercn javiercn added this to the 9.0-preview7 milestone Jun 3, 2024
@Junjun-zhao
Copy link
Member Author

Thanks @javiercn for looking into this issue so quickly. This issue has been added to 9.0-preview7 milestone, so it is not a blocker for .NET 9 Preview5, is it right?

@javiercn
Copy link
Member

No

@dewelloper
Copy link

No ?

@javiercn
Copy link
Member

javiercn commented Aug 1, 2024

@Junjun-zhao this was fixed in preview6, please give it a try with a newer SDK version

@javiercn javiercn closed this as completed Aug 1, 2024
@Junjun-zhao
Copy link
Member Author

@javiercn Verified this issue with dotnet-sdk-9.0.100-preview.7.24379.15, it has been fixed.

@robertmclaws
Copy link

I don't believe this has been fixed in Preview 7. I am now experiencing it in my projects. It happens when the .NET 9.0 SDK tries to build a .NET 8.0 WebAssembly project.

@robertmclaws
Copy link

robertmclaws commented Aug 16, 2024

@javiercn It looks to me like this line:

var staticWebAssets = CandidateAssets.Select(StaticWebAsset.FromTaskItem).ToDictionary(a => a.Identity);

needs to be changed to

var staticWebAssets = CandidateAssets.Select(StaticWebAsset.FromTaskItem).DistinctBy(a => a.Identity).ToDictionary(a => a.Identity);

But I could be wrong.

@Junjun-zhao
Copy link
Member Author

@robertmclaws We verified the affected three apps in our lab with .NET 9 Preview 7 build 9.0.100-preview.7.24407.12 , the issue does not repro that all of them could be built and published successfully. But they are not blazor web assembly apps. Are you using the .NET 9 P7 build 9.0.100-preview.7.24407.12? Do you have a demo or github project link?

@robertmclaws
Copy link

Output from dotnet --info:

.NET SDK:
 Version:           9.0.100-preview.7.24407.12
 Commit:            d672b8a045
 Workload version:  9.0.100-manifests.baed1e37
 MSBuild version:   17.12.0-preview-24374-02+48e81c6f1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.27686
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [aspire]
   Installation Source: SDK 9.0.100-preview.7, VS 17.11.35208.52
   Manifest Version:    8.1.0/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
   Install Type:        FileBased

 [wasm-tools]
   Installation Source: SDK 9.0.100-preview.7, VS 17.11.35208.52
   Manifest Version:    9.0.0-preview.7.24405.7/9.0.100-preview.7
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.7.24405.7\WorkloadManifest.json
   Install Type:              Msi


Host:
  Version:      9.0.0-preview.7.24405.7
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  6.0.417 [C:\Program Files\dotnet\sdk]
  7.0.407 [C:\Program Files\dotnet\sdk]
  8.0.203 [C:\Program Files\dotnet\sdk]
  8.0.301 [C:\Program Files\dotnet\sdk]
  8.0.400 [C:\Program Files\dotnet\sdk]
  9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk]

Luckily the solution I was trying to upgrade was OSS. If you pull down this codebase and try to build in on VS 17.12 Preview 1, you will run into the issue when you get to building CloudNimble.BlazorEssentials.TestApp.

But they are not blazor web assembly apps.

Can I ask why the team did not test these changes will ALL permutations of the new .targets file? WebAssembly is not an edge case, not testing this with those libraries seems like a MASSIVE oversight.

@Basyras
Copy link

Basyras commented Aug 17, 2024

Same here. After updating my VS preview version to 9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk], starting to see the The "DefineStaticWebAssetEndpoints" task failed unexpectedly. when building Blazor Wasm project,

@Junjun-zhao
Copy link
Member Author

Thanks @robertmclaws.

Hi @javiercn It prompts the same error message regarding "DefineStaticWebAssetEndpoints" task, but the stack trace is a little different from this issue. We have designed a minimal demo and file a new issue #57423 for tracking. Could you please take a look at? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

No branches or pull requests

6 participants