2022 wasm blazor.webassembly.js not found .net5 to .net6 upgrade

Viewed 622

I am trying to upgrade from a Blazor WASM .net5 project to .net6. I change the to net6.0 on all the projects. All compiles well, but I get a 404 error on loading blazor.webassembly.js

When I search for it from explorer I find it at: examgenerator\bin\Debug\net6.0\wwwroot_framework

while the request URL is: https://localhost:5001/_framework/blazor.webassembly.js

What am I missing?

2 Answers

It's quite easy to miss, but you need to ensure that your Client project is declared like this:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
    <TargetFramework>net6.0</TargetFramework>
    <!--The rest of your code here-->
</Project>

Notice that Microsoft.NET.Sdk.Web was changed to Microsoft.NET.Sdk.BlazorWebAssembly.


It's also important to have Microsoft.AspNetCore.Components.WebAssembly up to date.

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.4" PrivateAssets="all" />
</ItemGroup>

A diff tool like WinMerge is really helpful when looking for differences like this.

Note: There's a good chance that you'll run into some other issue (most likely hot reload related) while making such an upgrade. Until Microsoft comes up with a super clean solution to this, your best bet is to create a new .NET 6 project and move your code files there. This might of course be a frustrating option, but it's will save you so much more time.

Try to check if you have updated all your Nuget packages. Had this issue as well and had it resolved when I updated all my packages, particularly the Microsoft.AspNetCore.Components.WebAssembly package.

Related