I have an app/solution with multiple projects inside (.NET 6 - self-hosted Blazor WASM) It can build and run in debugging without any issues.
Now, i tried to publish it for testing in some of our local servers, and i try to publish it to a folder, and run as an .exe.
Problem is, when i try to publish it, somewhere after building succesfully, i receive the following error :
Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(412,5): Error : 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 Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupExistingStaticWebAssets(Dictionary`2 assemblyAssets, Dictionary`2 nativeAssets, Dictionary`2 satelliteAssemblyAssets, Dictionary`2 symbolAssets, Dictionary`2 compressedRepresentations)
at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.Execute()
Any ideas what could cause this ? I am using VS 2022 (Enterprise).
This error seems a lot like an open issue #37610 - Blazor AOT compilation fails at ComputeBlazorPublishAssets.GroupExistingStaticWebAssets
Here are the steps to further diagnose the problem:
You can capture a binary log with
dotnet publish /bland use MSBuild structured log viewer to look at the ComputeBlazorPublishAssets task. Within there, if you expand the parameters, it'll show all the ExistingAssets and you can get a better idea of what's happening. (You'll see the duplicated asset)
You can download MSBuild structured log viewer from here: https://msbuildlog.com/
I recommend you don't try to learn Blazor; it has too many problems, and when you try to update your project, you'll run into errors like the ones below that you won't be able to solve, not even with artificial intelligence. That's when you'll realize you wasted your time and that it would have been better to use Angular and Laravel. If you don't believe me, ask anyone if Blazor has more problems than other technologies. MONO_WASM: instantiate_wasm_module() failed LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
dt @ dotnet.runtime.js:3
dotnet.js:3 MONO_WASM: LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
d @ dotnet.js:3
blazor.web.js:1 Error in mono_download_assets: LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
Ar @ blazor.web.js:1
4dotnet.js:3 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
dotnet.runtime.js:3 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
2(index):1 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
blazor.web.js:1 Uncaught (in promise) Error: Failed to start platform. Reason: LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable
at you (blazor.web.js:1:163721)
blazor.web.js:1 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #38 "env" "mono_wasm_debugger_log": function import requires a callable