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.
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 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.
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
Press the Hot Reload icon in the toolbar, then Settings from the icon's context menu (or access via Tools > Settings > Debugging)
Disable "Enable Hot Reload and Edit and Continue when debugging"
Sadly I've been unable to get Hot Reload working while debugging, but its not really an issue for me.
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
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
In my case I made a stupid mistake of trying to Hot Reload an application run in Release configuration. Make sure it is Debug :)
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
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.
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.
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...
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"
For me there was another VBCSCompiler process that was running. Hot Reload worked after I ended that extra process in the Task Manager.
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
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.
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)
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 does work.
Sometimes it helps to save your project, close it. Shut dowm visual studio and start it again. Often errors disappear instantly..
I have an ASP.Net Core MVC simple project. When I start it without debugging (Ctrl + F5) and change any .cs File (Controller, for example), save it, and update the page in browser nothing happens. But it should automatically recompile and show changes, that was said in the book that I read.
Why can this happen?
I use Visual Studio 2019, .Net core 2.1.
If I manually close the page, and press start without debugging again it recompile and show changes in browser.
If I change .cshtml files (View) it takes effect as soon as I update the browser Page. So it is problem only with C# classes.
UPD dotnet watch works just fine for that purpose, but author of the book (A.Freeman, Pro ASP.Net core MVC 2 7th edition, chapter 6) did not use it:
Visual Studio supports detecting changes as soon as an HTTP request is received from the browser and recompiling classes automatically. To
see how this works, select Start Without Debugging. Once the browser
displays the application data, make the changes to the Home
controller. Save the changes to the controller class file and reload
the browser window without stopping or restarting the application in
Visual Studio. The HTTP request from the browser will trigger the
compilation process, and the application will be restarted using the
modified controller class
Why does this not work for me?
The book was written for Visual Studio 2017. It works as the book describes in VS 2017.
However, according to this, the auto-rebuild feature has not yet been added to Visual Studio 2019.
Original answer: (which applies when that feature is not available):
The difference is that .cs files are compiled into your project's DLL at compile time. For any new code to take effect, the DLL needs to be updated, which will only happen if you specifically tell it to recompile. This is why, when you deploy your project, you copy over the .dll file and not the .cs files.
However, views (.cshtml files) stay as plain text files and are compiled when you use them. If you edit a .cshtml, it's recompiled the next time the view is used. This is why, when you deploy your project, you do need to copy the .cshtml files.
Visual Studio does have a feature to let you modify .cs files while debugging and have it take effect immediately, but it doesn't support ASP.NET projects. It's called Edit and Continue.
However, you can setup dotnet watch to detect file changes and restart your application. There are instructions on how to do that here: Develop ASP.NET Core apps using a file watcher
I've searched and come across similar topics, but they all relate to ASP.NET core projects.
I have a traditional ASP.NET MVC web app using the .NET 4.6.2 framework.
When I run this project without debugging (CTRL + F5) I am able to see all changes made to html, js, and css files by simply refreshing my browser.
However, if I make a code change to a .cs file and refresh the browser the change is not shown. It obviously needs to be recompiled - if I then manually build the project, and then refresh the browser the latest change made to the .cs file is then visible.
Is there anyway I can make VS/IISExpress detect a code change, which then will automatically force the app to rebuild?
Here is an example of what I would like:
https://youtu.be/yyBijyCI5Sk?t=880
^ He modifies code (c#), saves the file, jumps back to his browser, hits refresh which then forces a recompile for a few seconds and then reveals the changes.
The project in this video is using ASP.NET core, so I guess automatic compilation is a feature of it.
Any ideas how to achieve similar for non-core asp.net projects?
Thanks
I dont know of any way to let browser force VS to rebuild project, however based on video. You could use something like link.
It is an extension which rebuilds your poject on save. So all .cs changes will be visible after save(build).
I dont personaly use it, just know it exists
Hope it helps.
Clear visual studio cache. step3 working fine for me.
Step 1: clear the Component Cache
Close Visual Studio (ensure devenv.exe is not present in the Task Manager)
Delete the %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache directory
Restart Visual Studio.
Step 2: cleanup your user’s temp folder
Delete the %USERPROFILE%\AppData\Local\Temp directory.
If all the above fails. you can try the hard route.
Step 3: delete the contents from the following folders
%USERPROFILE%\AppData\Local\Microsoft\Team Foundation
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio
%USERPROFILE%\AppData\Local\Microsoft\VSCommon
I recently started using Ubuntu as my development environment. I am using ASP.NET Core 2.0 and Visual Studio Code.
While I used Windows and VS2017 I was able to edit the views in my project and just reload the page and all the changes were there. I have a simple problem now while I am debugging in VSCode I am making my changes to the views but in order to see them in the browser I have to stop debugging and run the app again.
I am not sure if this is the right place to ask but I hope someone can help :)
You can use the dotnet watch run feature to review new changes to your web pages without having to stop, rebuild, and re-run.
See https://learn.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.1
I have a web project in Visual Studio.
When at work i can start the project in debug mode (F5), and set break points. Edit the Code Behind or asp controls. When pressing F5, this will refresh and my new code will be represented.
At my home computer i can edit, i can press F5, but my changes will not be shown. And the debugger will step through the code like it does not realize that it has come some new code.
Has anyone experienced this before? This is not the first time I have seen this, but i cant for the life of me figure out how to make it refresh....
Any pointers will be welcome :)
Edit:
Could this by any chance have something to do about the project type? Or the compilation of the web project?
I figured out why this worked as it did.
The project type i had chosen for my project was ASP.NET WEb Forms Application. This implies that the project will compile and be run from an DLL file.
To rebuild this everytime there is made a change is not possible, so it doesn't.
I changed the project type and buildt a Web Site instead. This kind of project does not compile into a DLL, but is rather run on the fly from the files that i code. Because of this i can make changes to my files, hit f5 and it will automatically reload with the new content.