In the early days of the .NET Framework, releases were infrequent and timed with Windows releases. The shift to an open-source platform brought a welcome change. Now, we anticipate an annual .NET release tied to the .NET Conf event every November.
Building on the foundation of .NET 7, this release introduces a host of new features. Understanding how your existing code adapts to this new version is crucial, and as experts in .NET, we wanted to guide you through some of the key features and changes we’re most excited about in .NET 8.
.NET 8: The Next LTS Release
The tick-tock pattern of STS (Standard Term Support) and LTS (Long Term Support) releases ensures a predictable support lifecycle for your projects. This release is the newest LTS version of .NET, meaning .NET 8 will have full support over the next two years.
This makes .NET 8 a great choice as an upgrade target for your existing applications, as well as a solid foundation for your new projects. You can benefit from the latest features and enhancements of .NET 8 without worrying about breaking changes or compatibility issues.
C# 12 Changes
Microsoft’s commitment to keeping things fresh is evident in the many changes to its most popular .NET language, C#. Here are a few changes of note:
- Primary constructors are no longer restricted to record types, allowing their use in any class or struct.
- Collection expressions bring a concise syntax for creating common collection values, supporting various collection-like types.
- The introduction of ref readonly parameters adds clarity for APIs using ref or in parameters.
- Default lambda parameters allow for default values in lambda expressions, similar to regular methods.
- The ability to alias any type, not just named types, provides semantic aliases for various unsafe types.
- Inline arrays, primarily used for performance optimization, enable fixed-size arrays within struct types.
- Finally, the introduction of the experimental attribute and interceptors, though still in preview, offer ways to modify code behavior at compile time. (Please note that interceptors are an experimental feature and are recommended for experimentation purposes only, not for production applications.)
For more detailed information on each feature, refer to the C# 12 release notes.
Revolutionizing Memory Management
For those immersed in building .NET code for cloud-native applications, a game-changing API awaits. Now, you have the power to dynamically adjust the memory limit for an application using the .NET garbage collector. This enables seamless scaling of app resource consumption based on demand, optimizing costs, and efficiency.
Elevating JSON Serialization
Managing JSON serialization and deserialization in .NET has been elevated to a new level in .NET 8, particularly with upgrades to System.Text.Json.
This library provides fast and easy serialization and deserialization of JSON data, with built-in support for additional types, such as Half, Int128, UInt128, Memory<T>, and ReadOnlyMemory<T>. It also supports customizing the handling of members that are not in the JSON payload, interface hierarchies, naming policies, read-only properties, and more. These upgrades align closely with modern hardware, making them invaluable for machine learning models and GPU computing tools.
.NET Is So Random!
Updates in .NET 8 empower you with new tools for randomness. This isn’t just about random number generation; it’s a direct way to use randomness as a selector in your code. The tooling allows for the seamless selection and shuffling of items in a set of data, a game-changer for machine learning applications.
Security and Performance in Focus
.NET 8 introduces support for SHA-3 as an alternative to SHA-2, bolstering hashing capabilities. Additionally, improved security features enhance privacy in connections, addressing web proxies over HTTPS.
As always, .NET 8 offers a huge step up in performance, just by retargeting your existing code.
One notable performance enhancement in .NET 8 is more support for native AOT (ahead-of-time) compilation. This means that you can compile your .NET code directly to native code, without relying on a runtime or an interpreter. This results in faster startup times, lower memory usage, and better performance. Improvements to AOT in .NET 8 include:
- Support for the x64 and Arm64 architectures on macOS.
- Reduction in the sizes of Native AOT apps on Linux, with potential size reductions of up to 50%. For example, a “Hello World” app on Linux x64 can now be as small as 1.84 MB compared to 3.76 MB in .NET 7, with certain optimizations.
- The ability to specify an optimization preference, focusing on either size or speed. By default, the compiler aims for fast code while considering application size. However, users can use the <OptimizationPreference> MSBuild property to prioritize one over the other.
ASP.NET Core 8
There are too many changes coming in ASP.NET Core 8 to mention them all here, so here are some details about some of the changes coming to Blazor and SignalR:
In .NET 8, Blazor has become a full-stack web UI framework, capable of rendering content at both component and page levels. It offers various rendering modes, including static server rendering, interactive server rendering, and client rendering using Blazor Server and Blazor WebAssembly. The framework also introduces a new Blazor Web App template, combining the strengths of Blazor Server and Blazor WebAssembly.
Other improvements include enhanced form handling, streamlined navigation, streaming rendering for improved user experience, and support for injecting keyed services. Blazor now allows access to HttpContext as a cascading parameter and enables rendering Razor components outside of the ASP.NET Core environment. Additionally, there are performance enhancements, error handling improvements, and added support for Content Security Policy (CSP) compatibility. Blazor Identity UI has been integrated to facilitate user authentication.
In .NET Core 8.0, a new approach has been introduced to set server timeouts and Keep-Alive intervals directly on HubConnectionBuilder. The default values are 30 seconds for ServerTimeout and 15 seconds for KeepAliveInterval.
withKeepAliveIntervalInMilliseconds methods when building a connection with HubConnectionBuilder. This is a departure from the previous approach in ASP.NET Core 7.0 or earlier.
withKeepAliveInterval for Blazor Web Apps and Blazor Server. Similarly, .NET clients can now utilize
Additionally, a new feature called SignalR stateful reconnect has been introduced to reduce downtime for clients facing temporary network disconnects. This works by temporarily buffering data on both the server and client, acknowledging received messages, and replaying any missed messages upon reconnection.
Ready for .NET 8?
If you are interested in upgrading your applications to .NET 8, or if you want to start a new project with this amazing platform, the team at Trailhead is here to help. We’ve been pioneers in the .NET ecosystem from the very beginning. With our expertise, we’re ready to assist you in upgrading to .NET 8 or embarking on new projects with confidence.
Contact us today to get started on this journey together!