MBeckius
MBeckius

Reputation: 1527

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)

Upvotes: 3

Views: 1125

Answers (5)

Apollo3zehn
Apollo3zehn

Reputation: 550

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

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

Upvotes: 5

jlbrandt
jlbrandt

Reputation: 1

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

Upvotes: 0

Rinaldi
Rinaldi

Reputation: 11

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>

Upvotes: 1

rayder2007
rayder2007

Reputation: 81

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

Upvotes: 0

Bryan Davis
Bryan Davis

Reputation: 13

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

Upvotes: 1

Related Questions