0

In .NET 6 we got the "Hot Reload" feature. C# is a compiled language, so this new feature feels like magic.

At a high level, how does it work?

And what are its limitations - can we expect improvements so that it will feel even more like interpreted languages, or is there a hard limit?

lonix
  • 14,255
  • 23
  • 85
  • 176
  • Note: I know what it is and how to use it. – lonix May 20 '22 at 13:50
  • 1
    It's not really new. Edit-And-Continue has been there since I think .NET Framework 2.0. – PMF May 20 '22 at 13:51
  • @PMF Good point. I wonder how they are related. – lonix May 20 '22 at 13:52
  • All it does is refresh the page. Any key modifications to model code requires a restart. That hot reload is for the browser to reload after HTML in the Razor Content is changed. But as for Model based code, the reload forces you to restart the application. – Mosia Thabo May 20 '22 at 13:53
  • If you view source on your browser, you'll realize that there's some JavaScript code added a the bottom of the page which is connected to the IDE via websocket. That's how the browser communicates with the IDE. – Mosia Thabo May 20 '22 at 13:55
  • @MosiaThabo You're referring to the `dotnet run watch` feature. That's not what I'm asking about. I'm asking about modifying loaded assemblies at runtime. – lonix May 20 '22 at 13:56
  • 3
    as @PMF says, I think most of the magic is built with Edit-and-continue which makes patches to the IL of the application as it's running; the IDE watches the files for changes; and the browser bits are fed with some websocket/javascript fancy stuff. I can't find anything from MS about the _how_, but Jetbrains posted this about how they did it in Rider: https://blog.jetbrains.com/dotnet/2021/12/02/how-rider-hot-reload-works-under-the-hood/ – TZHX May 20 '22 at 13:58
  • @Ionix ahh I see, well there's some tricky patching that happens. And the idea is still the same as Edit-and-Continue. Although they have automated the process from within the idea via command-line. After changing some code, your app recompiles real-time and only patches the new changes on the existing output. I believe the process is still the same, pause, edit, recompile, compare and patch the difference and continue... But the speed as which it's being done is just amazing. This mind be handful https://devblogs.microsoft.com/dotnet/introducing-net-hot-reload/ – Mosia Thabo May 20 '22 at 14:07
  • If you want to know the details you may want to start a discussion over at github with the roslyn folks. But i doubt you get more then a hint where to start in their sourcecode. – Ralf May 20 '22 at 14:18
  • @Ralf With all the drama surrounding hot reload before launch, I doubt they'll willingly offer any info. :) – lonix May 20 '22 at 15:27
  • Where's @EricLippert when you need him? – lonix May 20 '22 at 15:28
  • Eric Lippert isn't on the compiler team any more, has not for some years. But he might have a good idea. I think hot reload is a combination of E&C along with Javascript page reload. Hot reload of Winforms seems to be the same as the old E&C – Charlieface May 20 '22 at 18:04

0 Answers0