Reputation: 915
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.
Upvotes: 68
Views: 107025
Reputation: 21
Updating to .NET 9 seems to fix the issue for me, as i was getting the generic browser eception error, and hot reload wasn't even working with new blazor app template on .NET 8.
Upvotes: 2
Reputation: 1029
Specific for Blazor: 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 using Visual Studio prior the version 17.12.0 Preview 1.0.
Hot reload icon did not work at all for blazor apps.
The solution was quite simple. The app needs to be started without debugging ( Ctrl+F5 )
After that hot reload works fine even with older Visual Studio.
In VS 17.12.0 Preview 1.0 Hot reload works fine with Blazor in debug mode as well.
Upvotes: 48
Reputation: 308
This worked for me to fix the Hot Reload and Index.html file not getting updated:
Exit Visual Studio.
Go to this folder:
C:\Users_USER_\AppData\Local\Microsoft\VisualStudio\17.0_a24b1eed\WebTools
(17.0_a24b1eed) might be different.
Sort that folder by Date Modified.
Rename (or delete) to top folder.
I'm sure there's some other folder/file under that folder that can deleted and not lose all of settings (Startup Projects, etc.), but I didn't look into it too much.
Upvotes: 0
Reputation: 1
My solution is to add workloads. You should go to VS Installer and check the "Universal Windows Platform Development" checkbox.
Upvotes: 0
Reputation: 1340
I had a similar Hot Reload issue and the following steps helped me fix it.
bin
and obj
folders in your solution..vs
(hidden) folder in the solution root.And this is my (default) Hot Reload settings:
Hope this might help someone.
My original answer: https://stackoverflow.com/a/77699053/826611
Upvotes: 2
Reputation: 1031
I started getting this error seemingly out nowhere but was able to resolve it eventually. I'm not sure of both steps are necessary but what i did was:
I reset the VS Debugging options, as seen here: Tools -> Import and Export Settings
I restarted VS
Upvotes: 5
Reputation: 1
I am going to post this just in case, but my issue with it was that when saving it was not hot reloading. Setting it from the hot reload dropdown fixed it for me.
(Edit as I am unable to post images: Hot Reload drop down --> Hot Reload on File Save)
Upvotes: 0
Reputation: 53
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.
Upvotes: 1
Reputation: 45
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.
Upvotes: 1
Reputation: 117
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.
Upvotes: 0
Reputation: 9610
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
Sadly I've been unable to get Hot Reload working while debugging, but its not really an issue for me.
Upvotes: 32
Reputation: 186
Sometimes it helps to save your project, close it. Shut dowm visual studio and start it again. Often errors disappear instantly..
Upvotes: 1
Reputation: 2243
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.
Upvotes: 6
Reputation: 1110
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
- With your project open, select the "Project" tab, then choose "appname Properties…".
- Select "Debug" on the left pane.
- Check the "Enable native code debugging" box to enable it. Uncheck it to disable it.
(emphasis mine)
Upvotes: 5
Reputation: 381
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.
Upvotes: 1
Reputation: 21
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
Upvotes: 2
Reputation: 183
For me there was another VBCSCompiler process that was running. Hot Reload worked after I ended that extra process in the Task Manager.
Upvotes: 0
Reputation: 29
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"
Upvotes: 2
Reputation: 60832
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
Upvotes: 16
Reputation: 749
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...
Upvotes: 1
Reputation: 587
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.
Upvotes: 3
Reputation: 2046
In my case I made a stupid mistake of trying to Hot Reload an application run in Release configuration. Make sure it is Debug :)
Upvotes: 11
Reputation: 355
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
Upvotes: 7
Reputation: 4226
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
Upvotes: 4