Skip to content

Unable to build project using VS 17.12.3: “DiscoverPrecompressedAssets” task failed unexpectedly #59625

Closed

Description

@fltrierweiler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've found a similar issue, but the exception there isn't the same (System.ArgumentException there and System.InvalidOperationException here) and that issue was closed without an answer, so I've decided to create a new one.

Basically, I'm unable to build an existing project that uses Blazor.BrowserExtension.Template. It used to work fine with version 17.11.35219.272.

Expected Behavior

Simply put, the project build should work without errors, as it used to do.

Steps To Reproduce

I've created a minimalistic project to showcase the issue. To reproduce the error, all that has to be done is to build the project.

Exceptions (if any)

Here's the error I get whenever I try to build the project using VS 17.12.3:

The "DiscoverPrecompressedAssets" task failed unexpectedly.
System.InvalidOperationException: Fingerprint for '...\ExtensionTest\ExtensionTest\obj\Debug\net8.0\browserextension\build\BackgroundWorker.js' is not defined.
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.Validate()
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

.NET Version

9.0.101

Anything else?

UPDATE: If I use SDK 8.0.404 and specify the version by adding a global.json to the solution folder, it actually works. Still no way to work with 9.0.101, though.

Activity

  1. ghost added
    area-blazorIncludes: Blazor, Razor Components
    on Dec 23, 2024
  2. MarcoMedrano commented on Dec 24, 2024

    @MarcoMedrano

    I have the same issue building my maui app, your workaround is working (as I did not update my projects to dotnet 9):

    global.json at root directory:

    {
      "sdk": {
        "version": "8.0.206"
      }
    }
  3. added this to the 9.0.x milestone on Jan 7, 2025
  4. lofcz commented on Jan 10, 2025

    @lofcz
    Contributor

    Hitting a similar error after upgrading from 8 to 9:

    Error MSB4018 : The "DiscoverPrecompressedAssets" task failed unexpectedly.
    System.ArgumentException: An item with the same key has already been added. Key: [path]\wwwroot\app.css
       at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
       at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       at System.Linq.Enumerable.SpanToDictionary[TSource,TKey](ReadOnlySpan`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
       at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
       at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
    

    In csproj, I have several files linked as:

    <Content Include="..\[path]\wwwroot\**\app.scss">
        <Link>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</Link>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    

    If I remove these links, the app builds but I can't use assets from the web project in the sln. This works as expected on 8.0.X

    This is caused by:
    https://github.com/dotnet/sdk/blob/1d3bf3b00bd92bc9eef62d56e97072425ea8d87f/src/StaticWebAssetsSdk/Tasks/Compression/DiscoverPrecompressedAssets.cs#L35C9-L35C106

    ToDictionary() crashes if source contains duplicate keys.

  5. evgenyvalavin commented on Jan 29, 2025

    @evgenyvalavin

    +1

  6. TechnoZamb commented on Feb 10, 2025

    @TechnoZamb

    bump!!!

  7. SirBirne commented on Feb 11, 2025

    @SirBirne

    This issue has persisted since SDK > 8.0.403 and I'm also looking forward to a fix.

  8. Lionel-Renaux commented on Feb 14, 2025

    @Lionel-Renaux

    As Github Copilot is being removed in 17.11, this is now beginning to be an issue as we cannot update without breaking our builds. The fix is in fact quite simple and already 2 PRs are open to fix it!

  9. LeeStevens318 commented on Feb 17, 2025

    @LeeStevens318

    bump

  10. MiroslavJuhasCamea commented on Feb 19, 2025

    @MiroslavJuhasCamea

    Hi, I'm hitting the same issue. VS Version 17.12.3. Project did not change for several months but suddenly it cannot be build.

    The "DiscoverPrecompressedAssets" 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.Dictionary2.Insert(TKey key, TValue value, Boolean add)
    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
    at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()`

  11. tbaggett-ebsco commented on Mar 27, 2025

    @tbaggett-ebsco

    +1

    We have also encountered this issue when attempting to update to .NET 9, based on Microsoft's recommendation that we do so in dotnet/maui#28475 to resolve the BlazorWebView component never being cleaned up when no longer needed in .NET 8.

  12. 35 remaining items

  13. lbrpsoftware commented on Jun 24, 2025

    @lbrpsoftware

    I'm on VS17.14.6 and dotnet 9.0.301 now.
    The bug seems the have been resolved

    Edit: VS17.4.7 🤗

  14. aminmashayekhi commented on Jun 24, 2025

    @aminmashayekhi

    @aminmashayekhi your issue seems different.

    Could you file a separate issue and provide a repro project so that we can investigate further?

    Switch the calendar type to Georgian resolved the bug!

  15. ruansilva123 commented on Jul 24, 2025

    @ruansilva123

    I'm using Visual Studio 22 and Dotnet 7. I resolved this issue by switching from the current branch to the main branch and rebuilding the API. When I returned to my current branch, the build succeeded.

    Maybe the problem was a build cache.🤔

  16. javiercn commented on Aug 2, 2025

    @javiercn
    Member

    We believe these issues were addressed by #48952 and #49020 that are available in 9.0.301.

    The issue was that a cache was not being correctly recomputed, and we were introducing duplicates into the cache that caused issues in later stages of the pipeline.

    The original issue was addressed by deduplicating Content items before processing them as part of the pipeline.

    If you still experience issues after upgrading to .NET SDK 9.0.302, please file a new issue to let us know.

  17. 1944GPW commented on Nov 12, 2025

    @1944GPW

    Just encountered this problem when upgrading from .NET 9.0.307 SDK to .NET 10.0.100 under VS2022 Community (64-bit) Version 17.14.20, also removed all obj and bin and cleaned but it's still there,

  18. danroth27 commented on Nov 12, 2025

    @danroth27
    Member

    @1944GPW .NET 10 is only supported with VS 2026.

  19. frazambi commented on Nov 13, 2025

    @frazambi

    Still encountering this problem on both VS2026 and Rider 2025.3 on a .NET 10 project.

  20. bwinklesky commented on Nov 13, 2025

    @bwinklesky

    Still encountering this problem on both VS2026 and Rider 2025.3 on a .NET 10 project.

    @frazambi I think they want a new issue to be submitted.

    #59625 (comment)

  21. 1944GPW commented on Nov 14, 2025

    @1944GPW

    @1944GPW .NET 10 is only supported with VS 2026.

    That's interesting, I managed to build other solutions upgraded to .NET 10 on VS2022 17.14.20 without any problems. :)
    That aside, I installed VS2026, and still have the same issue as I posted above, and like others here.
    Also - just reopen this issue please as there seems to be no reason not to.

  22. tlevey01 commented on Jan 19, 2026

    @tlevey01

    Encountering this problem on VS2026 going from .Net 8 to .Net 10. Mine appears to be saying that blazor.web.js is the duplicate file, but I can't find where it's duplicated and none of the other fixes for the error work.

  23. LeeStevens318 commented on Jan 20, 2026

    @LeeStevens318

    I was able to reproduce the error when a RCL and Web Project has the same package.
    Here's example: https://github.com/LeeStevens318/csharp-discover-precompressed-assets

    Which worked fine on .net 8, but caused an issue when upgrading to 9/10.

    Microsoft Visual Studio Community
    January 2026 Feature Update
    Channel: Stable
    Version: 18.2.0

  24. tlevey01 commented on Jan 21, 2026

    @tlevey01

    @LeeStevens318 thank you! Unfortunately, I had already checked this and in my case, the only shared package is: Microsoft.AspNetCore.App.Internal.Assets.

    In my working .Net 8 version, I have 7 top-level packages shared by the project that won't build in .Net 10 (and over 271 that are Transitive). After upgrading to .Net 10, I have only one shared package (Microsoft.AspNetCore.App.Internal.Assets, which doesn't exist in my .Net 8 projects) and only 71 Transitive packages. The main project builds and runs, but this other project fails to build because of the "An item with the same key has already been added" error.

    I can't remove Microsoft.AspNetCore.App.Internal.Assets (a note reads: "Implicitly referenced by an SDK. To update the package, update the SDK to which it belongs."). Any ideas?

  25. danroth27 commented on Jan 22, 2026

    @danroth27
    Member

    @tlevey01 This issue is closed, so if you're still having this problem, please open a new one so that can triage it for investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions