Hot Reload is the most significant developer productivity feature in .NET 6. The ability to modify running code and see changes instantly—without stopping, recompiling, and restarting—fundamentally changes the development feedback loop. In this comprehensive guide, I will explain how Hot Reload works under the hood, what changes are supported, and how to configure it for optimal performance across different project types.
Understanding the Architecture
Hot Reload is powered by EnC (Edit and Continue), a feature that has existed in Visual Studio for decades but was limited to debug sessions. .NET 6 extends this capability to run without the debugger attached, making it available during dotnet watch sessions.
flowchart LR
Developer["Developer Saves File"] --> Roslyn["Roslyn Compiler"]
Roslyn --> Delta["Generate IL Delta"]
Delta --> Runtime[".NET Runtime"]
Runtime --> Apply["Apply to Running Methods"]
style Roslyn fill:#E1F5FE,stroke:#0277BD
style Runtime fill:#E8F5E9,stroke:#2E7D32
When you save a file, Roslyn (the C# compiler) analyzes the change and generates an “IL delta”—the minimum set of instructions needed to update the running assembly. The .NET runtime then applies this delta to in-memory types. If a method is currently executing, the change applies to the next call.
What Changes Are Supported
Not all code changes can be hot-reloaded. Understanding these boundaries prevents frustration during development.
Fully Supported
- Modifying method bodies (the most common case)
- Adding or removing lines inside methods
- Changing string literals and numeric constants
- Modifying lambda expressions and LINQ queries
- Adding new static methods to existing classes
- Changing Razor component markup (.razor files)
Requires Restart
- Adding new classes or types
- Changing method signatures (parameters, return type)
- Adding fields to classes
- Modifying constructors
- Changing inheritance hierarchy
- Modifying static constructors or type initializers
Configuration for Different Project Types
ASP.NET Core Web API
Hot Reload works out of the box with dotnet watch:
dotnet watch run
Changes to controller methods apply immediately. The next HTTP request uses the updated code. Session state is preserved.
Blazor WebAssembly
Blazor WASM supports Hot Reload for component changes. However, because the app runs in the browser, the delta must be transmitted over SignalR:
dotnet watch run --project MyBlazorApp
Edit a .razor file, save, and watch the browser update instantly. Component state is preserved unless you’re changing the component’s state structure itself.
Console Applications
For long-running console apps (workers, daemons), Hot Reload is invaluable. Changes apply to the next iteration of your main loop:
while (true)
{
ProcessData(); // Hot Reload changes apply here on next iteration
await Task.Delay(1000);
}
Visual Studio vs CLI Experience
Visual Studio 2022 provides the richest Hot Reload experience:
- Apply Code Changes button: Manual trigger (useful for batching changes)
- Apply on Save: Automatic application when you save (configurable)
- Edit and Continue UI: Visual feedback showing what changed
The CLI (dotnet watch) is simpler but effective. It automatically detects file changes and applies them. Use the --no-hot-reload flag if you need traditional restart behavior.
Troubleshooting Common Issues
“Rude Edit” Messages
When Hot Reload cannot apply a change, you see a “Rude Edit” notification. This means the change requires a restart. Common causes:
- Adding a new class
- Changing interface implementations
- Modifying generic type constraints
Hot Reload Not Working
Ensure your project targets .NET 6.0+ and that you’re running in Development mode (ASPNETCORE_ENVIRONMENT=Development for web apps).
Performance Impact
Hot Reload has minimal runtime overhead. The delta application is a memory operation that completes in milliseconds. There is no measurable performance penalty in production (Hot Reload is disabled by default in Release builds).
Key Takeaways
- Hot Reload dramatically accelerates the inner development loop
- Use
dotnet watchfor CLI or Visual Studio 2022 for IDE experience - Method body changes are fully supported; structural changes require restart
- Blazor and ASP.NET Core benefit the most from Hot Reload
- Zero performance impact in production
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.