???? Update 4: Microsoft has released .NET 6. It is claimed to be the fastest .NET till date.

???? Update 3: On Oct 23, Microsoft has inverted its decision to remove the hot-reload feature from .NET 6 release after facing massive open source community objection.

???? Update 2: On Sep 14, 2021 Microsoft has released ‘Release Candidate 1’ for .NET 6. By using this, you can get early access to production use features.

???? Update 1: On Aug 10, 2021 Microsoft has released Preview #7 for .NET 6. This is going to be the last preview before Microsoft releases the official version for .NET 6.


.NET 5, the previous version of the .NET framework, was supposed to completely unify .NET in November 2020 but failed to do so due to the Covid-19 pandemic and several other issues.

.NET 6, the new version of the .NET framework, will complete the tech giant’s plan to unify .NET development. In November 2021, it will be released as a Long-Term Support (LTS) release.

Let’s explore what .NET 6 brings to the table.

???? New Features and Enhancements in .NET 6

1. SDK Workload

Microsoft has come up with a new .NET SDK feature- SDK workload that supports new kinds of application –mobile and WebAssembly without enhancing the size of the SDK.

The SDK workload feature has been modified to add list and update verbs. 

  • .NET workload list- tells application developers which workloads have been installed.
  • .NET workload update- updates all installed workloads to the latest available version. 

.Net 6 Features – In a Nutshell

2. Inclusion of Compile-Time Source Generator

Almost all .NET serializers make use of a reflection mechanism for the object serialization process. But the reflection mechanism doesn’t work for high-performance cloud-native applications. This mechanism creates problems for startup, memory usage, and assembly trimming.

That’s why for the .NET 6 release, the .NET development team has introduced a new source generator at compile time as part of System.Text.Json. Source generators create C# source files that can be compiled as part of the library or software build.

By introducing the source generator feature in .NET 6, users can have the below-listed benefits:

  • Decrease in start-up time
  • Better serialization throughput
  • Lesser use of private memory
  • Eliminate runtime use of System.Reflection and System.Reflection.Emit

⚡ Interesting Fact: Bing.com & Official .NET website are currently running on .Net 6 Preview #1


3. Support for OpenTelemetry Metrics

Microsoft has been adding support for OpenTelemetry to the recent .NET versions in order to aim at observability. In .NET 6, the tech giant added support for the OpenTelemetry Metrics API. By providing support for OpenTelemetry Metrics, applications can easily interoperate with other OpenTelemetry systems.

4. Support for OpenSSL 3

OpenSSL is an open-source cryptography toolkit for TLS and SSL protocols. The .NET 6 will leverage OpenSSL 3 if it is available. Otherwise, the latest version of .Net will use OpenSSL 1.x.

5. Added More Roslyn Analyzers

Roslyn analyzers help in inspecting the code of a given application development project to find issues related to style, quality and maintainability, and design.

In .NET 5, Microsoft shipped around 250 Roslyn analyzers with the .NET SDK. The tech firm is introducing some more analyzers as part of the .NET 6 release.

6. Enable WebSocket Compression

Compression of information is imperative in data transfer via transmission protocol over the internet. Data compression helps in reducing storage space, transmission time, and communication bandwidth. This results in saving huge operational costs. In .NET 6, WebSocket compression is enabled.

WebSocket is a bi-directional and full-duplex computer communication protocol to transfer data between server and client.

For .NET 6, Microsoft used the per message-deflate extension for WebSockets, RFC 7692 to compress WebSockets message payloads with the help of the DEFLATE algorithm.

7. Removing Support for Older .NET Framework versions

In .NET 6, Microsoft will remove the support for any framework that is older than the below listed versions:

  • .NET Framework 4.6.1
  • .NET Core 3.1
  • .NET Standard 2.0

8. Supports Socks Proxy Protocol

SOCKS is an Internet protocol that facilitates transferring network packets between a client and server via a proxy server. 

In the present times, anonymity is increasing each day over the internet. Internet users are using VPNs, gateways, and proxies to hide their identities on the internet. And this is possible with the help of a common protocol known as SOCKS proxies.

SOCKS proxies were defined in the ’90s. But it was never supported by .NET. In fact, in the year 2016, an issue was logged for adding SOCKS support

Finally, .NET 6 supports SOCKS proxies protocol.

9. Advancement in Microsoft.Extensions APIs

In the .NET 6 release, you will have an improvised version of Microsoft.Extensions APIs. The .NET team has worked on hosting & dependency injection. 

Well, Dependency injection (DI) is a programming technique that enables a class independent of its dependencies.

10. Enable Custom Guards for the Platform Compatibility analyzer

The CA1416 Platform Compatibility analyzer already identifies platform guards via methods in OperatingSystem/RuntimeInformation, such as OperatingSystem.IsWindows and OperatingSystem.IsWindowsVersionAtLeast

However, the analyzer is unable to identify any other guard possibilities such as the platform check result cached in a field or property, or complex platform check logic is defined in a helper method.

In order to identify any custom guard possibilities, .NET engineers added new attributes SupportedOSPlatformGuard and UnsupportedOSPlatformGuard for annotating the custom guard members with the respective platform name and/or version. This annotation helped the Platform Compatibility analyzer’s flow analysis logic to easily recognize the custom guards.

Default Font Setting for Windows Forms

In the latest .NET version, you can now set a default font for an application with Application.SetDefaultFont. 

class Program

{

    [STAThread]

    static void Main()

    {

        Application.SetHighDpiMode(HighDpiMode.SystemAware);

        Application.EnableVisualStyles();

        Application.SetCompatibleTextRenderingDefault(false);

+       Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8f));

        Application.Run(new Form1());

    }

}

You can see the two examples after setting the default font with two different fonts.

Microsoft Sans Serif, 8pt:

Default Font Setting for Windows Forms 1-min

Image Credit: Microsoft

Chiller, 12pt:

Default Font Setting for Windows Forms 2-min

Image Credit: Microsoft

Initially, the default font was updated in .NET Core 3.0. But the update made a huge barrier for some users migrating .NET Framework apps to .NET Core. 

However, this new update in .NET 6 makes it possible to choose the required font for an application and also eliminates the aforementioned migration issue.

11. NuGet Package Validation Tool

In .NET 6, a Package Validation tool is provided to NuGet library developers to check that their packages are consistent and well-created.

.NET developers can leverage this tool to validate below points: 

  • Validate whether there are any breaking changes or not across versions.
  • Validate whether the package has the same group of public APIs for all runtime-specific implementations.
  • Find out any target-framework- or runtime- applicability gaps.

You can avail of this tool via the Microsoft.DotNet.PackageValidation.

12. Enable a Single Objective-C Interop

The .NET team has been allowing support for Objective-C with the objective to have a single Objective-C interop implementation for .NET. Previously, the Objective-C interop system was created around the Mono embedding API but later the team decided that it wasn’t the appropriate way to share across runtimes. 

.NET engineering team has developed a new .NET API to enable a single Objective-C interop that works on both runtimes.

13. .NET Hot Reload Available for ASP.NET Core & Blazor Projects

Hot Reload allows developers to alter the source code of an application in the running state, without pausing manually or using a breakpoint.

Now in .NET 6, the .NET Hot Reload is available for ASP.NET Core & Blazor projects with the help of dotnet watch.

14. Interface Casting Improvement

The performance of Interface casting has been scaled up by 16 percent to 38 percent, which is specifically helpful for C# pattern matching to and between interfaces.

15. Faster Handling of Struct Values in Dictionaries

In .NET 6, a new unsafe API — CollectionsMarshal.GetValueRefOrNullRef — has been introduced to handle struct values in Dictionaries quicker. This API is particularly for high-performance scenarios and is not applicable to general purposes. This new unsafe API lowers the key hashing to 1 from 2 and also eliminates all the struct copy operations.

16. Addition of a New Collection- PriorityQueue

A new collection – PriorityQueue<TElement, TPriority> (System.Collections.Generic) is introduced in .NET 6. This enables adding new items with a value and a priority. On dequeue, this new collection returns an item with the least priority value. 

PriorityQueue and Queue<T> are very much alike but each enqueued item has a priority value that impacts the behavior of dequeue.

Look at the sample code that shows the behavior of PriorityQueue<string, int>.

// creates a priority queue of strings with integer priorities

var pq = new PriorityQueue<string, int>();

// enqueue elements with associated priorities

pq.Enqueue("A", 3);

pq.Enqueue("B", 1);

pq.Enqueue("C", 2);

pq.Enqueue("D", 3);

pq.Dequeue(); // returns "B"

pq.Dequeue(); // returns "C"

pq.Dequeue(); // either "A" or "D", stability is not guaranteed.

17. System.Text.Json – ReferenceHandler.IgnoreCycles

In .NET 6, JsonSerializer (System.Text.Json) supports the ability to ignore cycles when carrying out a serialization process on an object graph. The ReferenceHandler.IgnoreCycles and Newtonsoft.Json ReferenceLoopHandling.Ignore options are alike. But the two options have an important difference. 

The implementation of System.Text.Json replaces reference loops with the null JSON token instead of avoiding the object reference.

You can look at the following sample code of ReferenceHandler.IgnoreCycles. In this example, the Next property is serialized as null instead of making a cycle.

class Node

{

    public string Description { get; set; }

    public object Next { get; set; }

}

void Test()

{

    var node = new Node { Description = "Node 1" };

    node.Next = node;

    var opts = new JsonSerializerOptions { ReferenceHandler = ReferenceHandler.IgnoreCycles };

    string json = JsonSerializer.Serialize(node, opts);

    Console.WriteLine(json); // Prints {"Description":"Node 1","Next":null}

}

18. Improvement in Parsing of Standard Numeric Formats

There is an improvement in the parser for the standard numeric types, particularly for .ToString and .TryFormat

Now with an improved parser, you will get better results when precision is greater than 99 decimal places. Apart from that, now the parser performs better with trailing zeros in the Parse method.

19. Improving the client app development

Currently, in .NET, Mobile App Development is provided as a separate Xamarin product. However, the Microsoft team has been working to make Xamarin much alike to mainline .NET. 

Now with .NET 6, the .NET team will offer a completely unified mobile product for .NET.

In .NET 6, iOS, Android, and MacOS app development will be integrated into the .NET SDK and leverage .NET libraries.

20. Improve .NET Inner Loop Performance

Performance is one of the key aspects of all .NET releases. In .NET 6, Microsoft has improved the .NET inner loop performance. This new .NET version will assist application developers to be productive by optimizing the development tools and workflows that are repeatedly used for performing code modifications, building, and testing.

21. Monitor New SDK Versions with Version-Checking Command

A new command- dotnet sdk check, is added to .NET 6 to track whenever any new version of SDK and Runtimes are available. 

This new command will tell you about the latest available version of the .NET SDK and .NET Runtime.

 

????.Net 6.0 for Linux, macOS & Windows : Download 

 

22. Single-File Bundles Support Compression

In .NET 6, Single-file bundles support compression. This can be enabled by changing the property EnableCompressionInSingleFile to true. During runtime, files are in decompress mode. 

Compression can save massive space for some scenarios. And increase the startup time of an application, particularly on Unix platforms.

You can have a look at single file publishing in both compression and decompression mode.

 

Without compression: 172 MB:

Single-File Bundles Support without Compression-min

Image Credit: Microsoft

With compression: 71.6 MB:

Single-File Bundles Support with Compression-min

Image Credit: Microsoft

23. IL Trimming Warnings Enabled

Trimming is a feature that was introduced in .NET Core 3.1 and 5.0. This feature in the .NET SDK analyzes the complete code of an application and eliminates all unused code before publishing an application.

Generally, the trimming feature works well but sometimes it gives breaking behavior and finds it very hard to trace down the root cause.

And there is another feature called trim warnings. Whenever a trimmer is unable to understand the code pattern, a warning will pop up.

 Earlier, trimming warnings were disabled by default. But now in .NET 6, it is enabled by default.

The following two are the categories of warnings:

  • RequiresUnreferencedCode
  • DynamicallyAccessedMembers

24. Crossgen2 Tool

Crossgen is a tool that offers ahead-of-time (AOT) compilation for a code to minimize the requirement for JITing at runtime.

Now in .NET 6, crossgen is replaced by Crossgen2. It is a new tool that allows developers to create and optimize code in a new way.

25. Dynamic Profile Guided Optimization (PGO)

PGO is a native compilation technology that assists developers to create more highly optimized code.

It is performed via a 2-step process: 

  • To store information about execution.
  • Leverages that recorded information to develop an improved binary.

.NET 6 has come with a dynamic PGO for enhanced performance as per runtime information that can be used for faster startup, higher throughput and smaller binaries.

26. .NET multi-platform app UI (.Net MAUI)

.NET MAUI is a cross-platform UI toolkit, offering a single stack that supports all platforms- Android, iOS, macOS, and Windows.

As part of the .NET unification journey, Xamarin.iOS and Xamarin.Android will be part of .NET 6.

27. Build Blazor Desktop Apps

Blazor is a popular open-source web framework to create .NET web apps. Earlier, Blazor was supported on the server and then on a browser with WebAssembly. In .NET 6, the tech giant is extending the support to create Blazor desktop apps. Blazor desktop allows developers to build hybrid client apps, which blend together web and native UI in a native client application.

Wrapping Up

You can learn about .NET 6 on .NET Conf 2021 a free,3-day, virtual developer event. The conference will be organized by the .NET community and Microsoft.  This year in the month of November, .NET 6 will be officially released along with ASP.NET Core 6 and EF Core 6.

hire-asp-developer-cta-banner