The .NET Stacks #45: 🔥 At last, hot reload is (initially) here

Hey, hot reload is here! We also talk about C# updates.

Dave Brock
Dave Brock

Happy Monday! Here’s what we’re talking about this week:

  • One big thing: .NET 6 Preview 3 is here, and so is hot reload
  • The little thing: C# updates
  • Last week in the .NET world

.NET 6 Preview 3 is here, and so is hot reload

On Thursday, Microsoft rolled out .NET 6 Preview 3. Richard Lander has the announcement covered. As he notes in the post, the release is “dedicated almost entirely to low-level performance features.” For example, we’ve got faster handling of structs as Dictionary values, faster interface checking and casting thanks to the use of pattern matching, and code generation improvements. The team resolved an issue where NuGet restore failed on Linux thanks to previous certificate issues. There were also updates to EF Core and ASP.NET Core.

Oh, and initial hot reload support is finally here.

Hot reload isn’t just for Blazor developers to enjoy—it’s built into the .NET 6 runtime. With Preview 3, you can use it by running dotnet watch in your terminal with ASP.NET Core web apps—Razor Pages, MVC, and Blazor (Server and WebAssembly). In future updates, you’ll enjoy Visual Studio support and use it with other project types like mobile, console apps, and client and mobile apps.

It’s been highly requested, and for a good reason—front-end frameworks and libraries based on interpreted languages like JS have enjoyed this for the last five years, and it’s a fantastic productivity booster. It’s easy to rag on Microsoft for taking this long—but they’ve had more significant problems during this time. Five years ago, Microsoft was preparing the roll out of the first version of .NET Core, and a component library like Blazor was just a thought, if at all. Now, the runtime is ready to address these issues (as it’s a main goal of .NET 6).

I tried out hot reload with Blazor Server this weekend (a blog post is coming). I’ll include some GIFs that show what it’s like.

Here’s basic editing of static text:

Here’s what happens when I update C# code:

In the following example, you’ll see here that it preserves state. When I change the currentCount value, the state of the component is maintained. I’ll need to refresh the page to see the new currentCount.

Here’s where I put it all together by dropping in components (with independent state) and editing some CSS for good measure.

However, not all code actions are supported. When this happens—like renaming a method—it will revert to current dotnet watch behavior by recompiling and refreshing your page with the latest bits.

If you have runtime errors, a banner displays at the top with the appropriate information. When you resolve your issues, the app will recompile and refresh.

On the subject of Blazor, Preview 3 ships with a BlazorWebView control. This allows WPF and Windows Forms developers to embed Blazor functionality into existing .NET 6 desktop apps.


The little thing: C# updates

Last week, Bill Wagner announced open-source C# standardization. In addition to the compiler work repo (in dotnet/roslyn) and the repo for C# language evolution (dotnet/csharplang), there is now a new repo (dotnet/csharpstandard) dedicated to documenting the standard for the latest C# language versions.

The new repo sits under the .NET Foundation, and as Wagner states:

Moving the standards work into the open, under the .NET Foundation, makes it easier for standardization work. Everything from language innovation and feature design through implementation and on to standardization now takes place in the open. It will be easier to ask questions among the language design team, the compiler implementers, and the standards committee. Even better, those conversations will be public … The end result will be a more accurate standard for the latest versions of C#.

If you’re having trouble distinguishing between dotnet/csharplang and dotnet/csharpstandard, you aren’t alone. Bill Wagner notes that there’s some overlap between the repos, and it’s a work in progress.

Speaking of C#, it’s nice to check out any language proposals from time-to-time, and file-scoped namespaces is making progress as a C# 10 proposal.


🌎 Last week in the .NET world

🔥 The Top 3

📢 Announcements

đź“… Community and events

🌎 Web development

🥅 The .NET platform

â›… The cloud

🔧 Tools

📱 Xamarin

🏗 Design, testing, and best practices

🎤 Podcasts

🎥 Videos

.NET Stacks