It looks like that lockdown was not hard for Microsoft. This year, the Plenty’s Horn opened and we had a shower with new software products — the long-awaited Windows 11, and the new Visual Studio 22, and, of course, .NET 6.0. This is good news in these bad times.
Let's talk about the new product, which is the most interesting for developers — .NET 6.0. Hardly developers ported their projects to NET 5.0 when a new version was released. I will go forward to tell the obvious truth that version 6 is not something fundamentally new - it is the “finished-off” fifth version. Most changes include modified or revised solutions from last year's release, but the sixth version received LTS (Long Time Support) status — it became a version with long-term support. From now on, this will be the case for all even versions.
As you remember, starting with .NET 5.0 Microsoft decided to merge all its frameworks into one. This was done to get rid of the "heterogeneity". That is, we came to the original concept of the .NET Framework, but now it is not a monolith, but looks like this.
There are a lot of changes and additions in NET 6.0. To make this article more than just a tedious treatise, I will briefly review the main, most interesting ones:
1. Crossgen2 - Pre-compilation
The updated Crossgen utility now had a second version. The old pre-compilation technology was, let’s have it straight, imperfect, and only enabled generating native code for the platform where the old crossgen utility was running. Now it enables running the JIT compiler regardless of the platform using different strategies and optimizations depending on the situation.
2. Profile-Guided Optimization (PGO)
It is a compiler optimization to prioritize the compilation of application parts. The point is that not all parts of the program are used during execution or are used extremely rarely. For example, some exotic else if branches. We can improve application performance if we point to frequently executed areas. Now you can turn on the analyzer, which, during the execution, will determine frequently and rarely used areas, and also generate an optimization profile. There are three optimization scenarios:
- Static – the code is split into frequently and rarely executed (hot-cold splitting). In this case, the optimization profile is generated only once. If the operating conditions of the application change, you will have to generate it again and re-optimize it. This approach complies with the most frequently executed areas of the application and places them together in the executable file. This will load it very quickly, thanks to the cache. Very rarely executed code is not compiled. If necessary, it will be compiled during the execution of the application.
- A dynamic approach where no preliminary optimization profile is generated. The analyzer monitors the execution of the application during real operation and recompiles sections of the code if the optimization is required.
- The mixed approach speaks for itself. Here both approaches are used. That is, the application is optimized according to the optimization profile. It is then adjusted during operation according to a dynamic scheme.
3. Hot reload
You probably remember something like "Edit and Continue". We had the opportunity to change the code at runtime, but it was not very convenient. You had to set breakpoints and pause the application. The breakpoint had to be set before the moment to be debugged. Edit possibilities were also very limited.
Now we can fix the code right at runtime while debugging. Then save the changes and see them in real time. This greatly speeds up the debugging process, especially if you know what and where to fix and want to see the result immediately without restarting the debugger. And yes, it now works in VS Code as well. The list of available changes is short and is available here.
4. .NET MAUI
As part of globalization or combining all the frameworks, Microsoft is adding support for Xamarin. Now we have developments for macOS, iOS, and Android in VisualStudio. However, this will not work in the standard SDK. You will need to install the optional Optional SDK Workloads. In fact, development is becoming more and more convenient. Creating a project on Android is a matter of a team:
They decided to abandon the name Xamarin and now presented the Multi-platform App UI or MAUI.
5. Minimal API Framework
It is worth talking about an interesting tool Minimal API. This framework enables to make do with minimal code for creating and accessing web methods. You don't need to create the MVC binding, customize the controller and method headers to build up the routing. Moreover, you won’t need Setup.cs either. All you need is Program.cs where you can immediately develop web methods with routing.
app.MapGet("/", (Func<string>)(() => "Hello World!"));
The unnamed function will return "Hello World!" for any query. This is exactly what is needed for microservices or prototyping.
6. Supported operating systems
Microsoft has published a list of all supported operating systems, namely:
- Windows — Windows Client, Windows 10 Client, Windows 11, Windows Server, Windows Server Core, Nano Server;
- Linux — Alpine Linux, CentOS, Debian, Fedora, openSUSE, Red Hat Enterprise Linux, SUSE Enterprise Linux (SLES), Ubuntu;
- Mobile — Android and iOS.
7. ARM64 architecture support
ARM64 support was implemented in NET 5 for Windows. In the sixth version, it was expanded to the ARM64 Apple processors.
8. Blazor desktop app support
While Blazor is a framework for web-based applications, Microsoft decided to break the mold and enable developing desktop applications. Blazor has probably proven its worth.
9. MSBuild optimization
Razor compiler was merged to Roslyn Source Generators, which significantly accelerated the build. Roslyn Source Generators was introduced in NET 5 and made a stir with its possibility to generate C # code on the fly while developing.
Developers also worked on our favorite LINQ. With every .NET release, they add something new to this language (especially in .NET 5) and this release was no exception. LINQ has been made faster over the past few years and the code duplication was reduced. Here is a small list of useful features:
- The TryGetNonEnumeratedCount function enables to determine the count of items in a sequence without enumerating them, thereby significantly speeding up the application in some cases;
- The Chunk function splits the items of the sequence into a specified number of groups;
- The MaxBy and MinBy functions allow you to find the maximum or minimum element for a given key selector;
- The DistinctBy, ExceptBy, IntersectBy, and UnionBy functions also allow you to perform actions according to a key selector;
- The ElementAt and ElementAtOrDefault functions return the element from a specific index with the difference of returning a default value;
- The FirstOrDefault function finally can set a default value. “Your prayers have been answered”, because not everyone was happy with null;
- The Max function now can accept a comparator to compare values;
- The Take function enables to set a range.
Well, how we could forget modifications to the System.Text.JSON library. The main changes were made to the serializer. Namely:
- Avoiding circular references;An object IAsyncEnumerable <T> was added, which turns into an array;
- Deserialization of an array document, where the DeserializeAsyncEnumerable method appeared.
- Support for source generators - a technology of serialization without reflection, which significantly speeds up and reduces the cost of the application;
- New interfaces IJsonOnDeserialized, IJsonOnDeserializing, IJsonOnSerialized, IjsonOnSerializing were added, which contain event handlers of the same name. That is, you can execute any code during serialization/deserialization;
- You can set the order of field serialization using the JsonPropertyOrder attribute;
- Deserialization from a stream;
- Another very interesting "feature" is the support for working with JSON documents as with DOM. This feature is quite useful because sometimes you just don't want to spawn POCO objects for simple operations. Do not forget that the DOM approach to work with JSON reduces performance and overuses resources. We are assured that this will not happen, but we will find out in practice how true this is.
The HTTP communications protocol has been around for ages. Everyone knows that it is based on another protocol, TCP, which has been around for even longer. Yes, the rapid development of the Internet has put http in a difficult position - it looks like a weak link against the growth of network bandwidth. Finally, we got the third version of this wonderful protocol. It did not eliminate the problems but significantly reduced their degree.
The new QUIC protocol, which replaced TCP, is faster if packages are lost. It is faster during the connection setup. It allows for parallel data transmission. Moreover, it is inherently secure thanks to encrypted queries.
13. Priority queue
A new class has appeared — PriorityQueue <TElement, TPriority>. It allows you to set the priority on each added item and creates a priority queue. These items are removed starting with the lowest priority.
Developers also worked with the date. Some of the most interesting modifications:
- There are two new methods System.DateOnly and System.TimeOnly, which allow you to work directly with a date or time, and not DateTime as before.
- Conversion of time zones. That is, you can now use the Windows or IANA identifier when determining a zone using the TimeZoneInfo.FindSystemTimeZoneById method. If the search does not find the identifier of a zone of one type, then the time is automatically converted to a different format according to the second type of identifier.
15. C# 10 support
We can write a separate article about the new features of version 10. I will not even mention the most interesting here. You can check out this list of changes.
Let's sum up - what does .NET 6 offer:
- Performance. Indeed, the .NET 6 platform is very fast with various optimization features, especially when it comes to the web part.
- Versatility. It is one platform for creating any application for different platforms. Many were positive about this idea. The learning curve became lower and it is convenient. However, there are also enough skeptics. We all know that the versatile is usually worse than something special.
Of course, we tested our products for compatibility with the new framework. FastReport operates on .NET 6 just as well as on version 5.
We can say that there is a right vector to consolidate platforms, languages, and technologies. Yes, the younger generation has the fewer technical knowledge, but we no longer need them. Just like an automatic gearbox displaces a mechanical one. People just should drive and not think about gears and engine rpm. Like many modern developers do not want to get into the technical buzzwords of certain processes. Now they can enjoy the creative aspect of software development.