49

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
bob mason
  • 677
  • 1
  • 6
  • 11
  • But what is your question? What do you expect of us? VS2022 is not released yet. I.e. bugs are expected. Did you report this to Microsoft? – JHBonarius Oct 30 '21 at 09:32
  • Yes I did, but I don't know how long it'll take, I just want to know how to set the COMPLUS_ForceENC environment variable, nothing came on google regarding this variable! – bob mason Oct 30 '21 at 23:15
  • There are a number of hits when you google "COMPLUS_ForceENC". But it might not be the solution to your problem. – JHBonarius Oct 31 '21 at 08:04
  • 2
    I just installed the 2022 RTM and I am getting that issue on a .NET Core 3.1 Web API Project when I do a very simple code change. – Airn5475 Nov 08 '21 at 20:49
  • 1
    Hot reload is not working on Cshtml files in .NET Core 3.1 MVC application either. – Amir Zare Nov 09 '21 at 15:51
  • 3
    Official version is out now but I'm experiencing the same issue. Anyone reported this yet? Any page we could follow for this? – Baz Guvenkaya Nov 19 '21 at 01:33
  • From the outside, I'm trying to help Microsoft get this fixed. Do you have anything **helpful** to add? Maybe even a polite "I've experienced this too" with any details you can muster. Examples of how MS might reproduce failures when running from Visual Studio would be helpful, I think. **https://github.com/dotnet/aspnetcore/issues/45519** Perhaps that is the main issue to track this, since it has some responses? Also relevant: * https://github.com/dotnet/aspnetcore/issues/45190 * https://github.com/dotnet/aspnetcore/issues/44568 * https://github.com/dotnet/aspnetcore/issues/39715 – Patrick Szalapski Feb 08 '23 at 23:20

18 Answers18

39

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.

walter33
  • 776
  • 5
  • 12
  • 5
    Indeed. I'm actually building a Blazor Wasm hosted in ASP.NET Core and HOT RELOAD doesn't work at all even with CTRL-F5. Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.5 – Marc Roussel Jan 17 '22 at 13:02
  • I was doing this with a web project. Almost gave up on it as I have been doing a control f5 debug for 20 years.. this solved the issue of the Hot Reload not working in visual studio because I was running though IIS / IIS Express – hanzolo May 11 '22 at 21:21
  • 20
    How does MS think this even tenable? Pretty much the only reason I ever want to hot reload is after fixing an issue I discovered WHILE DEBUGGING? What use is this if you can't debug and hot reload? – Ryan D Oct 07 '22 at 16:48
24

Late to the party, but today this started driving me nuts as stepping in the debugger threw this issue every single time I went to the next statement.

Solution for me was

  1. Press the Hot Reload icon in the toolbar, then Settings from the icon's context menu (or access via Tools > Settings > Debugging)
  2. Disable "Enable Hot Reload and Edit and Continue when debugging"

enter image description here

Sadly I've been unable to get Hot Reload working while debugging, but its not really an issue for me.

EvilDr
  • 8,943
  • 14
  • 73
  • 133
  • 3
    I had this same issue. I was getting the error message just by stepping through the debugger! Turning this off resolved the problem. – Brandon Tull Nov 17 '22 at 17:58
  • @BrandonTull I had same issue, just by pressing F10 to do a step in the debug, caused the message to appear, which is crazy, a clear bug. Once I restarted visual studio the issue dissapeared. – Yogurtu Jan 18 '23 at 13:26
  • 3
    Hot reload was working fine in Debug until just now, and I have no idea what changed. Being able to use it only without debugging is pretty useless. – Grault Feb 07 '23 at 21:43
  • 2
    VS 17.4.5 right now and these options are checked and disabled. Hot reload is still not working at all while debugging – Marc Roussel Feb 16 '23 at 14:39
  • @marc-roussel I saw the options disabled too (VS 17.5.0), but then realized I had the Debugger turned on. Once I stopped the Debugger I was able to modify (e.g. disable) those checkboxes. – Nevermore Mar 02 '23 at 11:56
  • 2
    best solution is to turn that rubbish off. It bugs at random, rebuilding doesn't help, only restarting windows. Almost 1 year later and Microsoft still hasn't fixed – CodeMonkey Jun 18 '23 at 13:28
7

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

Hugo A.
  • 218
  • 2
  • 12
  • 1
    Thanks, that's actually my problem exactly! i am not sure what is missing or how to "fully migrate" to .Net6 ! – bob mason Dec 01 '21 at 20:09
  • tryed to update and hot reload while debugging, still doesn't work for me even with an out-of-the-box project using the .net6 template. – Mosè Bottacini Dec 02 '21 at 15:24
  • Mine resolved after updating from 17.0.0 to 17.0.2. It's sort of bugs that destroy Rockets! – Ayub Dec 03 '21 at 16:50
  • 1
    I have now opened an Issue in Dotnet Github. You can follow the issue there. https://github.com/dotnet/aspnetcore/issues/38809 – Hugo A. Dec 07 '21 at 19:14
  • 1
    Blazor WASM hot reload does NOT work - tested extensively on VS Code and VS2022 with .net 6.0.100. – Greg Dec 13 '21 at 19:22
  • @Greg did not test that out, but you should post that in the issue I opened in github. They should know about it. – Hugo A. Dec 15 '21 at 14:59
  • Given up posting issues in github - they release stuff and then "pretend" its working and the train moves on. – Greg Dec 15 '21 at 18:10
  • https://developercommunity.visualstudio.com/t/blazor-hot-reload-not-working/1480369 Sayed Hashimi from microsoft says it does NOT work on release 17.0.3 - Im am in agreement. – Greg Dec 15 '21 at 18:27
4

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

Mosè Bottacini
  • 4,016
  • 2
  • 24
  • 28
  • 1
    Its extremely misleading - showing videos of Blazor server side hot reload working but NOT saying that this does not work on wasm. I have wasted so much time on this and submitted 5 different bug explanations throughout the preview versions and the release version. No more - just a huge waste of time. – Greg Dec 13 '21 at 19:42
4

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

Robert Synoradzki
  • 1,766
  • 14
  • 20
4

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

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
2

In my case , it was due to I have not used hotReloadProfile in my launchSettings.json file:

"IIS Express": {
    "commandName": "IISExpress",
    "hotReloadProfile": "aspnetcore", 
    "launchBrowser": true,
    "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
1

In my case, it was due to I have disabled Razor Source Generator <UseRazorSourceGenerator>false</UseRazorSourceGenerator> in the .csproj file. Setting it back to true fixed the issue.

Noctis Tong
  • 459
  • 1
  • 7
  • 17
1

Might help someone. I removed reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation in my Web project and code in my startup and HotReload working now...

Tim Maxey
  • 749
  • 6
  • 13
  • "code in my startup", what code? please elaborate... – OJB1 May 31 '22 at 20:25
  • @OJB1 what seemed to work for me was to REm this out //services.AddRazorPages().AddRazorRuntimeCompilation(); I also removed the reference from the Web project in VS (didn't need it anymore) – Tim Maxey Jun 01 '22 at 21:07
1

While trying to resolve a separate problem, I enabled native debugging in my project, which caused this problem. After disabling it again, I'm able to hot reload.

https://www.technipages.com/visual-studio-native-code-debugging

  1. With your project open, select the "Project" tab, then choose "appname Properties…".
  2. Select "Debug" on the left pane.
  3. Check the "Enable native code debugging" box to enable it. Uncheck it to disable it.

(emphasis mine)

Grault
  • 974
  • 12
  • 31
1

I know this might be one of the very first things most people will try, but I just restarted Visual Studio and it worked again.

Lukas
  • 1,699
  • 1
  • 16
  • 49
0

For me there was another VBCSCompiler process that was running. Hot Reload worked after I ended that extra process in the Task Manager.

Scott Jodoin
  • 175
  • 2
  • 8
0

I also had problems with hot reload not working, the cause was this line:

app.UseResponseCompression();

See more info her:
https://github.com/dotnet/aspnetcore/issues/43939#issuecomment-1245382809

0

Another reason I'm finding for Hot Reload not working is that there's UI changes already occurring when the Hot Reload is triggered.

I have found that if I execute my hot reload on a page too quickly, it will throw the hot reload error. However if I turn inspect on and wait for all page / network updates to stop before I hit hot reload, the hot reload will succeed.

This works in Blazor WASM both in and out of the Debugger.

misterbee180
  • 325
  • 1
  • 13
0

I was facing the same problem. Hot Reload was not working.

I was using VS 2022 and .Net Core 6 and using the service like this

builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

When I remove

AddRazorRuntimeCompilation()

Hot Reload work.

0

Sometimes it helps to save your project, close it. Shut dowm visual studio and start it again. Often errors disappear instantly..

Paul Albers
  • 121
  • 1
  • 8
0

Had the same problem.

My fix was to only have ONE startup project. Removed my API as a startup project and ran my .Net MAUI app as a single project.

Hope this can help someone out there.

0

In my case the problem started after having enabled the native code debugging. I set debugger process (back) to 'Managed only', and that fixed the problem.

Hobbe51
  • 43
  • 7