question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WebAssembly hot reload support broken when changing environment from Development

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When launching Blazor WASM standalone application via dotnet watch (behind the scenes launching a dev server to host it) hot reload support is broken when host environment is changed to anything else than Development. In the browser’s console it reports:

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)

Also _framework/blazor-hotreload.js is not loaded and is not fetched (not causing 404 errors).

Related: #35194 #37462

Expected Behavior

Hot reload feature should not depend on the environment’s name? If it definitely should then please make it bolded in the documentation. Developers are often customizing these names, e.g. Local for the local development machine which breaks the functionality.

Steps To Reproduce

Change ASPNETCORE_ENVIRONMENT in the project’s launchSettings.json from Development to anything else.

Exceptions (if any)

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

.NET Version

6.0.100

Anything else?

.NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff

Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc

.NET SDKs installed: 3.1.416 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
andylegearcommented, Feb 1, 2023

Confirming same issue here, when ASPNETCORE_ENVIRONMENT is Local. VS 17.1.0. Changing ASPNETCORE_ENVIRONMENT to Development “fixes” the issue, but would prefer not to have to make that switch.

I experienced this exact issue. Confirming that the switch of the ASPNETCORE_ENVIRONMENT back to Development in my profile fixed the problem

1reaction
lonix1commented, May 19, 2022

I think I read somewhere that hot reload doesn’t work when any non-default environment variables or switches are used. Which is confirmed by basic testing - when you change any option it stops working, when you add switches it stops working. But if you keep the defaults (which includes the development environment) then it works.

Also debugging + hot reload don’t work at the same time.

I hoped it would be fixed in the latest v6.0.300 (from a few days ago), but unfortunately I still get the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot Reload not so hot. : r/Blazor
Some nuget packages will break it silently. Somehow the WASM project got a reference to System.Drawing or something and it broke hot reload....
Read more >
Hot Reload For CSS Not Working With Blazor ...
According to the documentation*, hot reload is supported by WebAssembly when running without a debugger. I can't understand why only the CSS hot ......
Read more >
Update on .NET Hot Reload progress and Visual Studio ...
NET 6, developers can now Hot Reload almost any type of .NET Code (in code-behind or Razor pages) in both ASP.NET Core and...
Read more >
Introducing the .NET Hot Reload experience for editing ...
Simply make a supported change while your app is running and in our new Visual Studio experience use the “apply code changes” button...
Read more >
Hot Reload for .NET 6 in Rider 2021.3
Shortened times between a code change and it being reflected in our application's output can make or break our flow. Hot Reload is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found