Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Hot Reload on Visual Studio 2022

I moved my web app from Visual Studio 2019 to 2022 (Preview 7) but I am unable to hot-reload even small changes like changing if(a=b) to if(a!=b) and will require stopping the debugger, and I am unsure what is the 'COMPLUS_ForceENC' environment variable, couldn't find anything about it.

When I create a new web app, hot reload works very well on C# and cshtml.

this is the error shown when I change anything to my original app:

Error ENC2004: Changes made in project require restarting the application: Changes are not allowed when the debugger has been attached to an already running process. Consider setting 'COMPLUS_ForceENC' environment variable before launching your process.

like image 802
bob mason Avatar asked Oct 30 '21 09:10

bob mason


People also ask

How do you use 2022 vs hot reload?

When using Visual Studio 2022 and starting your app with the debugger, you can hot reload a native C++ application when running under the debugger (F5) using the Hot Reload button. Hot Reload is also supported for apps built using CMake and OpenFolder projects. This experience is powered by native Edit and Continue.

How do I enable hot reload in Visual Studio?

On Windows, check the Enable XAML Hot Reload checkbox (and the required platforms) at Tools > Options > Debugging > Hot Reload. In earlier versions of Visual Studio 2019, the checkbox is at Tools > Options > Xamarin > Hot Reload.

How do I reload Visual Studio?

To refresh the currently active view Choose Refresh from the Window menu, or click the Refresh button in the toolbar.

How do I turn off hot reload in Visual Studio?

We've changed these settings in the next preview so that hot reload is controlled solely from the Tools\Options\Debugger\Enc&Hot Reload option page, and these settings will only apply when you turn off Hot Reload for Ctrl+F5.


5 Answers

I was blaming VS for un-functional Hot Reload, but in my case it was caused by trying to Debug ( F5 ) and hot reloading at the same time. Hot reload icon enter image description here did not work at all for blazor apps.

The solution was quite simple. The app needs to be started without debugging ( Ctrl+F5 ) enter image description here

After that hot reload works fine.

like image 103
walter33 Avatar answered Oct 23 '22 04:10

walter33


Might be a coincidence, but after updating from 17.0.1 to 17.0.2 it started working. It's strange because in the update log there's no mention to such a bug fix. Try updating to the latest version.

UPDATE Seems that I only got this working on my new .NET 6 project. In the old one migrated to .NET 6 this still happens. Maybe in projects that are not fully migrated to .NET 6 and still using the old startup.cs file won't work correctly. In debug mode, the update notification shows up, but content does not change until a browser refresh.If not in debug mode, refreshing the browser does nothing.

UPDATE 2 Found out that in a new .net 6 Asp.net Web page project, the Hot reload works well if I change .razor files, but in .cshtml files I need to refresh the browser to see changes. I have both file types because I'm using razor pages + Blazor in the same project.

If you try to create a .Net 6 Blazor project I'm almost sure Hot Reload will work.

UPDATE 3 I have now opened an Issue in Dotnet Github. You can follow the issue there. github.com/dotnet/aspnetcore/issues/38809

like image 6
Hugo A. Avatar answered Oct 23 '22 04:10

Hugo A.


In my case I made a stupid mistake of trying to Hot Reload an application run in Release configuration. Make sure it is Debug :)

enter image description here

like image 3
Robert Synoradzki Avatar answered Oct 23 '22 06:10

Robert Synoradzki


VisualStudio 2022 GA version doesn't works for me either :( looks i'm not the only one, i've noticed i've a icon for the hot reload function different from the one shown in the Microsoft promotional videos, mine is a flame, while the working version seems to have two flames that forms a circle :(

i've found this

*In Visual Studio 2022 GA release Hot Reload support for Blazor WebAssembly when using the Visual Studio debugger isn’t enabled yet. You can still get Hot Reload If you start your app through Visual Studio without the debugger, and we are working to resolve this in the next Visual Studio update.

if i start the program without debugger attached I have Hot Reload, or i can run the app with the debugger without the hot reload, which is expected by the article linked above but the Launch Event is quite misleading as they never mention this nor shown which button is pressed during the demos to start blazor webasm with hot reload working... Anyway they doesn't show debugger and hot reload working together for blazor webasm, so it looks like it's all in our minds :( ... we need to wait

like image 2
Mosè Bottacini Avatar answered Oct 23 '22 04:10

Mosè Bottacini


First of all, hot reload should work for both Ctrl + F5 and F5 debugging, so the accepted answer is wrong.

In my case hot reload was not working because my debug configuration was named differently than "Debug", it was named "LocalDebug" (but I did set all the settings correctly).

There's an issue at MS's github here: https://github.com/dotnet/aspnetcore/issues/43910

like image 1
Alex from Jitbit Avatar answered Oct 23 '22 04:10

Alex from Jitbit