Focus on full-stack Blazor web framework as .NET 8 RC2 and new Visual Studio preview arrives

Focus on full-stack Blazor web framework as .NET 8 RC2 and new Visual Studio preview arrives
Bare metal

Microsoft’s .NET 8 Release Candidate 2 is out, and the last release candidate of what will be a long-term support release includes major updates to the Blazor web framework that “combine server and client based web UI development into a single cohesive model.”

General availability for .NET 8 is expected in November, but Microsoft is still adding features to key frameworks, especially ASP.NET. The new release includes numerous updates for the Blazor web application framework, including the much-anticipated Identity user interface which gives developers a pre-built user account management solution using either SQL Server or SQLite for the database management.

There is also a new preview of Visual Studio 17.8, which is needed for working with .NET 8. This release includes a new Problem Details window for C++ compiler errors, enabling navigation of the error details.

The Blazor web framework is perhaps the highlight of this .NET update. ASP.NET, the all-encompassing name for Microsoft’s .NET web frameworks, used to work in a way similar to PHP, rendering code on the server. By default it is a multi-page model and when event like button clicks are handled, the entire page is refreshed. Developers can get round this by using ASP.NET for a web API and writing the browser client code using a modern JavaScript framework; but some .NET developers prefer to write all their code with C#.

Blazor is a more recent approach that allows C# client code without this full-page refresh, as well as two-way interop between C# and JavaScript. It makes single page applications (SPAs) natural in ASP.NET for the first time. In the previous version of .NET, Blazor has three primary models:

  • Blazor Server is where the developer writes Razor components – HTML combined with C# code – which run on the server, and the UI in the browser is updated via the SignalR library, generally using WebSocket connections, sending only the difference in a binary format. A script in the browser called browserLink.js handles this interaction. 
  • Blazor WebAssembly is a single page application (SPA) framework where the browser hosts the .NET runtime ported to WebAssembly. The server compiles Razor components to .NET assemblies and sends these to the browser. 
  • Blazor Hybrid is where Razor components are used in desktop applications, using an embedded browser component hosted by MAUI (Multi-Platform App UI), Windows Presentation Foundation (WPF) or Windows Forms. 
New options for Blazor projects in Visual Studio 2022 17.8

Now in .NET 8 developers can mix and match. A new “rendermode” directive, which can be applied per component, per page or globally for the entire application, controls whether Server or WebAssembly is used. In addition, an Auto render mode uses the server initially, for fast initial page rendering, and then WebAssembly once the runtime has been downloaded to the client. Finally, a Static render mode is for HTML generated only on the server with no Blazor-driven interactivity, more like the old ASP.NET Razor Pages model.

The detail of how the render modes work is complex and there are some tricky compatibility issues with existing Blazor code; but this is a big improvement for Blazor. “We were so excited about the new Blazor capabilities that we jumped the gun developing a greenfield app for county government that needs to be shipped in November,” said one optimistic developer, in response to a post from Principal Program Manager Daniel Roth describing the latest update.

It does seem though that the framework is still somewhat in flux even though it is close to general availability and others may want to wait a few months in case of any initial issues.

There is also the matter of the tooling. The main options are either Visual Studio or command-line tooling combined with Visual Studio Code, for developers not on Windows or who prefer a lightweight editor. The late changes in the framework means that the tooling is playing catch-up for some features. Another complaint is performance issues, with one developer “currently experiencing nearly 100 seconds of CPU churn when I press a key in a .razor file in my solution,” despite having first raised the problem over a year ago. The mix of HTML, C# and JavaScript in a Razor or Blazor file is challenging for smart editor features.

Nevertheless, with the new Blazor .NET developers may be less envious of modern React-based JavaScript frameworks. Blazor Hybrid is also attracting increasing attention as a viable .NET solution to the tough problem of how best to code cross-platform desktop applications.