The best new features in .NET 6

Microsoft .NET 6 marks a new era of developing performant, modern-day applications for web, cloud, desktop, and mobile devices. Here’s what’s new.

The best new features in .NET 6
TNS Sofres (CC BY 2.0)

Microsoft .NET 6 is the culmination of the .NET unification that started with .NET 5. Cross-platform .NET 6 merges the .NET Core, .NET Framework, and Xamarin/Mono technologies into a single .NET Framework, unifying the SDK and runtime for desktop, mobile, web, and cloud applications. 

Microsoft made .NET 6 generally available on November 9, 2021, alongside C# 10 and Visual Studio 2022. In addition to an improved developer experience overall, .NET 6 brings significant performance boosts compared to its earlier counterparts. In fact, .NET 6 is the fastest .NET yet. It’s also a Long-Term Support (LTS) release, which means Microsoft will support .NET 6 for three years.

It goes without saying that you must understand the new features of .NET 6 before you can take full advantage of them. This article discusses what’s new in .NET 6 and what it means to go forward as a C# 10 developer. You can download a copy of .NET 6.0 for Windows, Linux, and macOS.

Note that .NET 6 is supported in both Visual Studio 2022 and Visual Studio 2022 for Mac. However, .NET 6 is not compatible with Visual Studio 2019, Visual Studio for Mac 8, or MSBuild 16. You will need to upgrade to Visual Studio 2022 if you wish to use .NET 6. You can download Visual Studio 2022 here.

A unified and extended .NET platform

.NET 6 provides a unified platform for desktop, mobile, web, cloud, and IoT applications. The underlying platform supports applications of various types and makes it simple to re-use code across all applications. New features and enhancements have been introduced to ensure that code executing in the cloud, on a desktop, or on a mobile device all behaves the same way.

One of the most enticing enhancements is the .NET Multi-platform App UI (.NET MAUI). You can now write code that provides a modern client app experience across desktop and mobile operating systems in a single project. .NET MAUI became generally available in May.

Note that neither .NET 5 nor .NET 6 is a replacement for the legacy .NET Framework. Microsoft has no plans to port Web Forms, Windows Communication Foundation (WCF), or Windows Workflow Foundation (WF) from .NET Framework to .NET 5 or .NET 6. However, there are supported alternatives for each of these technologies as shown below.

  • Web Forms can be replaced by ASP.NET Core Blazor or Razor Pages.
  • Windows Communication Foundation (WCF) can be replaced by gRPC.
  • Windows Workflow Foundation (WF) can be replaced by open source CoreWF.

What’s new in .NET 6

Let’s now look at the new features and improvements in .NET 6.

Improved performance

Performance is considerably improved, particularly for file I/O, resulting in reduced execution time, latency, and memory use. The FileStream class has been re-written to improve async file I/O performance. The implementation on Windows no longer uses blocking APIs, which makes it several times faster.

The Just in Time (JIT) compiler has been updated. There have been improvements in the garbage collector as well. System types such as Guid and string have been improved considerably.

Profile-guided optimizing

Profile-guided optimizing (PGO) is a compiler optimization technique and a new feature introduced in .NET 6 that allows the JIT compiler to generate optimized code according to the types and codes that are most often used.

Unified platform support

Microsoft’s work toward a unified platform for .NET applications started with .NET 5. The idea was to provide a uniform platform for developing apps that can run on any device and any operating system. Thus all .NET 6 applications, across web browser, desktop, cloud, IoT, and mobile devices, use the same .NET libraries.

New APIs introduced

New APIs have been added for HTTP/3, JSON, mathematics, and more.

Security improvements

There have been significant improvements in security, such as support for the ChaCha20Poly1305 encryption scheme, OpenSSL, and “defense in depth” runtime mitigations.

C# 10 and F# 6 improvements

The considerable improvements in C# 10 include the introduction of new lambda capabilities, record structs, and implicit using. There have been improvements to F# 6 as well that include pipeline debugging and Task-based async.

Improvements in JSON APIs

Improvements to JSON APIs bring more capabilities and enhanced performance. A new source generator for System.Text.Json has been introduced that eliminates the need for runtime reflection and code creation and allows for the production of appropriate serialization code at build time.

Improvements in cloud diagnostics

Cloud diagnostics have been enhanced with the addition of OpenTelemetry and dotnet-monitor, which are currently in production and accessible with Azure App Service.

Improvements in code quality

Source generators and analyzers have been introduced to help you write better, safer, and faster code.

Hot Reload

Hot Reload is one of the most striking new features added in .NET 6. You can take advantage of this feature to modify the user interface when your application is in execution. You can see the changes reflected as soon as you save them—you don’t need to restart the application. This feature boosts developer productivity considerably.

DateOnly and TimeOnly structs

This is a long-awaited feature in .NET. You can now set values to an object that is just a date or a time. Below are a few examples that illustrate how you could use DateOnly and TimeOnly structs.

var dateNow = new DateOnly(2021, 11, 17);
var newDate = dateNow.AddDays(7);
var timeNow = new TimeOnly(12, 0, 0);
var newTimeNow = timeNow.AddHours(5);

Support for async streaming

With .NET 6, you now have support for async streaming, using IAsyncEnumerable<T>, which allows you to stream data from the server without any buffering.

Targeting .NET 6

When you create a new .NET 6 application in Visual Studio 2022, the TargetFramework node should refer to .NET 6. A typical .csproj file created in .NET 6 will look like this:

<Project Sdk="Microsoft.NET.Sdk">

You can also specify a flavor of .NET 6 if you’re targeting a specific operating system:

  • net6.0-android
  • net6.0-ios
  • net6.0-maccatalyst
  • net6.0-tvos
  • net6.0-windows

What’s missing from .NET 6?

Note that some technologies were dropped in .NET 5. Hence, they are not a part of .NET 6 as well. These include the following:

  • ASP.NET Web Forms. The legacy ASP.NET Web Forms is no longer supported. You might want to use Blazor, Angular, or React instead.
  • Windows Communication Foundation (WCF). Microsoft had intended to bring WCF back to the .NET ecosystem, but dropped the idea after determining it would take some three years to do so. Microsoft recommends using gRPC, Google’s open source RPC framework, as an alternative. (For a guide, see my article here.)
  • Windows Workflow Foundation (WWF). WWF, a workflow framework that has been in use for many years, has being dropped from .NET as well.

The .NET release schedule

After the release of .NET 5, Microsoft promised to deliver a new version of .NET in November of every year. The following table lists the release schedule for .NET.

.NET Framework was deprecated after .NET 5 was released. This means you can still use .NET Framework on versions of Windows that support it. However, with Microsoft shortening the lifecycles of the operating systems, you could easily end up using a Windows version whose end-of-life has already arrived.

Microsoft provides Long-Term Support for .NET 6. It should be noted that LTS releases are usually supported for a period of three years from the date of release. Thus, Microsoft plans to support .NET 6 until November 2024. The next LTS release, .NET 8, is due in November 2023.

A new era of .NET development

From a better, faster, and unified runtime to an improved developer experience, the sweeping benefits of .NET 6 make it the most significant release in the .NET ecosystem since .NET 4. .NET 6 is both the fastest .NET yet, with a smaller footprint and reduced resource consumption, and the most developer-friendly, with many language enhancements and features like Hot Reload.

Most important, .NET 6 takes us a big step toward easing the development of cross-platform applications. It is a cross-platform framework that allows you to create native mobile and desktop applications for Android, iOS, macOS, and Windows, without having to maintain multiple codebases to support all these different platforms.

Microsoft .NET 6 not only establishes a new foundation for all future .NET platforms. It marks a new era of developing performant, modern-day applications for multiple operating systems and architectures in .NET. With a unified platform, better language maturity, and improved developer tools, .NET 6 is well set to be the default Microsoft development platform for years to come.

Copyright © 2022 IDG Communications, Inc.