aspnetcore: Unable to build project using VS 17.12.3: “DiscoverPrecompressedAssets” task failed unexpectedly
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.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 20
- Comments: 47 (6 by maintainers)
for me it was enough to install SDK 9.0.204 on top of the existing VS 17.14.0 installation, and fix the SDK version in the global.json to 9.0.204 (with rollForward disabled):
The fundamental issue here that the .net team needs to address is that this “we will not release out of band patches for the SDK” position is dangerous and causing problems.
They did this with Mac last September where they didn’t get a patch in quickly enough in April and then Sequoia (15) was released and every Mac user of .NET was SOL for a month if their system upgraded them automatically. Why? Because the .net team screwed up and didn’t get a fix in that they knew they needed and then refused to correct the problem with an out of band SDK patch with the fix.
This is the same thing. We have to fight this endlessly for a month because the .net team won’t release an out of band SDK patch to fix a major issue. (not quite as bad as “You can’t use .net on a mac” but getting there.)
This should be yet another object lesson that this is not a viable position.
For anybody encountering this issue, as a workaround you can add a target to the
Directory.Build.targetsor the.csprojfile which removes all duplicates fromStaticWebAsset:Repros for me as well, and it doesn’t need VS, it reproduces from the CLI.
Same Issue in:
Removing build paths (bin, obj, .vs) works again for a while.
I’m on VS17.14.6 and dotnet 9.0.301 now. The bug seems the have been resolved
Edit: VS17.4.7 🤗
+1
Unfortunately, as mentioned, this is only a quick stop-gap. Once your project builds successfully, from then on you will get the errors when building. Until you purge the bin and obj folders.
It worked for me after I manually removed the files in the “obj” folder
I just updated to .NET 10 Preview 4 SDK and VS 2022 17.4 Preview 7
I am now getting the same issue with a NuGet package I created. Is there something I need to do to in the package to prevent this?
If I add a Blazor web app project to the NuGet package solution and reference the project instead of the NuGet package, the app builds and runs fine and everything works.
The only way I could consistently work around this bug was, since this is just a test app, I moved the static files I had (in the wwwroot folder - originally I had an HTML file in there in order to deal with .NET removing built-in Swagger … booo) out of the project, and then I had to remove the
app.UseStaticFiles();(even with the wwwroot folder removed, even just callingUseStaticFiles()was somehow caching the “bad” files and I still got the errors, referencing the now-removed files).Something got messed up in 9.0.300…
Hitting a similar error after upgrading from 8 to 9:
In csproj, I have several files linked as:
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.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:
Having this same problem out of the blue. Nothing in this thread has worked. Solution does not build even on the first opening of Visual Studio.
I’ve found that removing the obj and bin folders do help the problem… until the next time you try and launch the app. Once the bin/obj folders are there, the bug is triggered again.
I am getting same. SDK 9.0.300.
Close VS and then reopen VS, Clean and Build can build once.
Posting here as a +1 this just happened to me as well. Although my experience is occuring in Azure DevOps build pipelines from seemingly an update which has broken my build pipeline.
Specifically, seems to have broken the build of one of my test projects:
I believe this issue is duplicate of https://github.com/dotnet/sdk/issues/49180, which was addressed by https://github.com/dotnet/sdk/pull/48952 for the upcoming 9.0.301 .NET SDK release and should be available in a couple of weeks. @javiercn Can you confirm?
bump.
This error is happening consistently on the latest update. Unable to run a project. Temporary workaround is to “Clean Build” then run it and that sometimes works or to restart visual studio if it gets stuck. Nothing works consistently.
Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.14.1
Error: Severity Code Description Project File Line Suppression State Error (active) MSB4018 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.Dictionary
2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer`1 comparer) at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() XXXX C:\Program Files\dotnet\sdk\9.0.300\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets 289Not sure what the ‘magic’ changes were, but it all works now. I started changing different Build properties on the tsconfig.json, package.json, etc. and how typescript builds the *.js and how webpack bundles the output. Now Visual Studio packages both my scripts as ‘staticwebassets’ and removes the config/configFiles sections from the package (which I think was causing the issue); which makes everything work now.
My GitHub project is here
Similar error in VS 2022 17.14 Preview 7 and the 9.0.300 SDK, but a different stack trace to the initial description’s:
Came to say “Me too”.
It does look like this started with the update to 9.0.300.
In my case, I see this in VSCode, running a simple API application. If I hit F5 to start the app, I get the error and the build fails.
If I then go into a terminal and enter the command
dotnet build- the build will complete without error. HittingF5again will build and launch the app.However stopping the app, making any edit and trying to
F5again will show the error again.I do not have 9.0.203 installed, so that work around doesn’t work. The addition to the csproj suggestion also did not work.
FWIW, this simple app has very little in the wwwroot folder (just basic css, etc.)
Here to comment on this lovely error I received after patch Tuesday. Why does every release break everything?
+1 can confirm this is happening to me, workaround by @AdmiralSnyder https://github.com/dotnet/aspnetcore/issues/59625#issuecomment-2880047135 helps.
Our workaround to this issue which out of a sudden came up with the release of .NET 9.0.5 / SDK v9.0.300 on 2025-05-13 was to to use a
global.jsonas described in https://github.com/dotnet/aspnetcore/issues/59625#issuecomment-2880047135 and pin the docker images used in the CD pipeline to
mcr.microsoft.com/dotnet/sdk:9.0.203andmcr.microsoft.com/dotnet/aspnet:9.0.4instead of just pinning major+minor9.0.The workarounds described in https://github.com/dotnet/aspnetcore/issues/59291 did not fix our issues.
Works Thank you @AdmiralSnyder
Yeah, getting the issue with SDK 9.0.300, too 😭
@G-MW, I confirmed your workaround resolved the issue for me. Thanks again for sharing it!