'Blazor .Net 6.0 Hot Reload

I have an asp.net hosted blazor wasm app that I just upgraded from 5.0 to 6.0. When trying hot reload either from VS 2022 or from dotnet watch run I get the following error in the browser console:

aspnetcore-browser-refresh.js:138

   Error: System.NullReferenceException: Object reference not set to an instance of an object.

at Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(String moduleIdString, Byte[] metadataDelta, Byte[] ilDeta) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) --- End of stack trace from previous location --- at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime jsRuntime, DotNetInvocationInfo& invocationInfo, String argsJson) at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson) at Object._convert_exception_for_method_call (https://localhost:44362/_framework/dotnet.6.0.0.qme34vl4fz.js:1:178709) at Object._handle_exception_for_call (https://localhost:44362/_framework/dotnet.6.0.0.qme34vl4fz.js:1:180678) at managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://mono-wasm.invalid/managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:20:21) at Object.invokeDotNetFromJS (https://localhost:44362/_framework/blazor.webassembly.js?version=32330328618b4ff08635274a6f31248c:1:42078) at g (https://localhost:44362/_framework/blazor.webassembly.js?version=32330328618b4ff08635274a6f31248c:1:1618) at Object.e.invokeMethod (https://localhost:44362/_framework/blazor.webassembly.js?version=32330328618b4ff08635274a6f31248c:1:2665) at Object.St.Te._internal.applyHotReload (https://localhost:44362/_framework/blazor.webassembly.js?version=32330328618b4ff08635274a6f31248c:1:56100) at https://localhost:44362/_framework/aspnetcore-browser-refresh.js:136:33 at Array.forEach () at applyBlazorDeltas (https://localhost:44362/_framework/aspnetcore-browser-refresh.js:134:12)



Solution 1:[1]

I was having the exact same issue, and ran across your post while trying to troubleshoot.

Much to my chagrin, I admit that the reason is due to running the Release build. I must have (somehow) changed it to the Release build at some point without realizing.

Once back on the Debug build (but without the debugger attached), Hot Reload is now working again.

Error in Visual Studio:

Error in Visual Studio

Error in Chrome:

Error in Chrome

Solution 2:[2]

Check inside your *.csproj project file to see if there is any configuration related to the target platform. If so, delete it and try again. For example:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>true</Prefer32Bit>
    <Optimize>True</Optimize>
</PropertyGroup>

Solution 3:[3]

We have resolved this issue by updating all Microsoft packages to the latest version.

Solution 4:[4]

For me, the issue was fixed by changing ASPNETCORE_ENVIRONMENT from Local to Development. More details here: https://github.com/dotnet/aspnetcore/issues/39269

Solution 5:[5]

I had to put UseStaticFiltes() AFTER UseBlazorFrameworkFiles(), otherwise the NullReferenceException occurs. This works for me:

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dada
Solution 2 Jeremy Caney
Solution 3 rayder2007
Solution 4 Jeremy Caney
Solution 5 Apollo3zehn