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)
I had to put UseStaticFiltes() AFTER UseBlazorFrameworkFiles(), otherwise the NullReferenceException occurs. This works for me:
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
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 Chrome:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With