What's New with .NET 9

November 19, 2024
Written by
Reviewed by

What's new with .Net 9

As of this week, the new update to .NET, .NET 9, is finally available. With a livestream kickoff and a detailed web page, Microsoft is urging developers to upgrade. For those looking to upgrade from .NET 8, the update process should be a smooth transition. Additionally, the new updates to .NET offer some new features and performance enhancements that developers will appreciate.

Following the release announcements this week, this blog post will take a look at the changes and upgrades to .NET 9. Those features include performance improvements, new support for cross-platform development, and built-in AI integrations that will allow developers to access a variety of third party AI APIs very smoothly.

What's new in .NET Aspire

Microsoft ran a three-day livestream last week to review the new features, so this blog post will discuss the highlights. The demos opened with a discussion of .NET Aspire. For those unfamiliar with Aspire, it consists of templates and pre-built tooling that allow easy real-time testing and security for creating production-ready applications.

Adding Aspire to a web app is easy, as it can be added directly in Visual Studio or VS Code. Microsoft provides a sample application on Github to get developers started. Detailed install instructions for the sample app are in the Aspire documentation.

A screenshot showing a basic ecommerce store created with the Aspire sample app.

Aspire applications include a detailed runtime dashboard that you can use to show the application and active resources. This dashboard is a one-stop source for application logging. It shows proper traces for both the requests your application is making and those being made to your application.

The column for Actions in the dashboard also allows you to create custom actions that might be unique to your application's needs. For example, you can create a custom one-click action to reset your database during early application testing.

Aspire's service discovery system allows you to reference services in your application by name instead of by address or port. This is useful if you are trying to integrate multiple services in your app. Aspire also includes Integrations, a curated set of NuGet packages that make it easy to integrate popular services like databases and cloud. With Aspire's Community Toolkit, you can contribute new integrations as well.

Even if you aren't a C# programmer, you can take advantage of Aspire. One way is by using its built-in Python integration. This has been available since .NET 8 for those who want to use Python for AI applications. With the release of Aspire 9, Microsoft is also previewing Azure Function support, which allows server-free Azure development with basic function creation.

Aspire installation requires .NET 8 or .NET 9. If you want containers for your application, you will also need a container runtime such as Docker. You can check out Aspire templates at the Aspire samples page on Github.

.NET MAUI

.NET MAUI is the most up-to-date and powerful way for .NET developers to create cross-platform applications. As the former Xamarin has reached its end of life cycle, MAUI is the recommended way to create applications that target Windows, macOS, Android, and iOS. MAUI applications create native application code for all of the platforms you target, allowing you versatility of platform while still having access to .NET tooling.

.NET offers choice for developers: Blazor for Websites and PWAs, Blazor + MAUI for Hybird, and .NET MAUI for Native applications.

New features for MAUI in .NET 9 include crushed bugs (see release details for the specifics, which largely impact cross-platform builds), and better testing infrastructure. There have been updates for enhanced performance as well as platform integrations.

Project templates

.NET MAUI gives developers the options to install MAUI project templates. These include sample data, models, folders, and pages that you can use to learn and improve your own applications. These code tools are designed for copy-pasting; just add them to your app so you can pick up the code and use it for whatever your app needs. Microsoft has also added a hybrid web view to enable reuse of components. This will make it easier to reuse the same code snippets between web apps when you translate it to native applications for iOS and Android.

Application Layout Live Preview

XAML allows a live preview of your application layout, a highly requested feature. This preview shows what the front end layout of your application will look like without having to run the backend logic. This is a helpful feature for designers, who can easily test changes to the look and feel of the app without having to recompile it. Embedded controls in the sample application allow an easy swap between light and dark mode, as well as showing off user avatars in avatar mode.

Have XAML live preview enabled in your preview settings to get access to this feature.
This screenshot shows an example of a live application preview alongside XAML code being edited.

Each new release of .NET MAUI will be supported for 18 months. Those developers still on .NET 8 have an additional 6 months of support remaining, while those upgrading to .NET 9 will be supported for 18 months — starting now — for all your Android and iOS cross platform applications. To keep your applications supported and up-to-date, upgrading is recommended.

Learn.Microsoft.com has extensive tutorials if you want to learn more about how to use .NET MAUI for your applications.

AI in .NET 9

Easy AI integrations are a top of mind concern for many developers today. In .NET 9, Microsoft is introducing Microsoft.Extensions.AI, built in support that allows for easy AI embedding in your applications.

A slide from .NET conference showing the support options for Microsoft.Extensions.AI.

AI integration enables semantic search. If you aren't familiar with the concept, semantic search allows a search in an application to find words with similar meaning to what a user is looking for, even if the word is not an exact match, by using a vector of similar words on a word cluster. This makes a search process more intuitive for users.

A new IChatClient tool

With .NET 9's new IChatClient tool, it's possible to build a stateful chatbot system that keeps track of the messages in your conversation. It can also point directly to custom functions your application creates or to your own databases or product manuals.

As an example, if you are creating a commercial chatbot that can be used to sell a product, using your own function to support its data means it knows the price of that product every time it is asked. The integration with LLM means it will understand customer questions better, and be able to answer general questions as needed if those questions are not in the scope of your own data.

Future posts will look directly at the code required to integrate these AI tools. But for now, lots of detail is available on Microsoft's Dev blogs.

What's new in C# 13

With the wide release of .NET 9 comes the release of C# 13. The newest version of C# offers some performance enhancements, as well as some forward-looking design that will pay off for developers when C# 14 arrives.

The best place to find details about this are on the C# product page which breaks down the specific changes and updates to the language. Highlights include a new lock object and new escape sequence. Also new to C# 13 is the Overload Resolution Priority, which allows developers to specify what code to target in the case of an overload. This can allow for more graceful error handling for your end users.

Params collections in C# 13 are giving developers more ways to interface with spans, which are a more efficient way to collect and compare on words and data than using arrays of strings. Microsoft considers this a "down payment" on the future, as C# 14 will make span first class. More ways of interfacing with natural language will make your AI-enabled projects run faster and more efficiently than before.

Runtime libraries and performance improvements

This look on the new features announced for .NET 9 will finish up with discussion of some of the performance enhancements that this update has added. The compiler has new improvements that will make applications run and compile faster. These changes should occur whenever you install .NET 9, even if you don't otherwise update or alter any of your code.

The move to open source has allowed the developer community to contribute to this release, creating new types of efficiency. Over 1,000 PRs were submitted to .NET 9 for performance enhancements alone.

100s of opensource contributors on Github helped create .NET 9.

If you want to see very specific details, Microsoft Engineer Stephen Toub has a blog post that discusses over 350 of these pull requests in detail. But if reading a post of hundreds of pages is too daunting, he mentioned a few of his favorite updates at the .NET conference. These favorites include:

  • Alternate Lookup methods: building on the ideas of spans instead of strings, these methods allow you to more quickly get matching values searching through text for matching spans. This search doesn't allocate memory the way string lookup does, but can store the spans you discover as strings if you request.
  • Memoryextensions.split and Regex.enumeratesplits: As a C# developer, you have probably used string.split — because you need it all the time; it's ubiquitous for chopping up bits of text. However, it's not as fast as it could be, since it has to allocate a string array for its results and then a string for every element in the array. Now, you can use splits for this, making it much faster to look up words without having to create string arrays.
  • Tensorprimitives. <T>: .NET 9 introduces a new library called System.Numerics.Tensors which allows you to create and perform math operations on Tensors. This will allow you to group data by doing math not on one floating point value, but a span of floating point values, another way to help group similar types of data.

Upgrading to .NET 9

NET Developers should have an easy time upgrading to .NET 9. The performance enhancements should work very quickly without any changes and updates to code. And the promise of easier AI integration should be very tempting for developers looking to take their applications to the next level. The .NET Conference has archived videos and demos for those wanting to take a closer look on their YouTube page.

For those who want to get started right away, .NET 9 can be installed from the .NET homepage.

Amanda Lange is a .NET Engineer of Technical Content. She is here to teach how to create great things using C# and .NET programming. She can be reached at amlange [ at] twilio.com.