What’s new in .NET 9, C# 13, Azure and VS2022

Overview

.NET Conf 2024 had plenty of new things to show off, unsurprisingly AI was the main focus, followed by .NET Aspire.

Below are all the things I found super useful in the flood of new versions just out.

AI

The jewel in the crown being the Microsoft.Extensions.AI (preview) library with key features:

  • Unified API for integrating AI services to your .NET apps
  • Loose coupling to easily switch between AI frameworks and avoid vender lock in
  • Current support for OpenAI, Azure AI, Mistral, Anthropic, ONNX, OLlama under their own nuget packages Microsoft.Extensions.AI.<platform> (some are community driven)
  • .NET Aspire integration

This new set of libraries works with and makes use of Semantic kernel functionality and does not replace it.

Abstractions like IEmbeddingGenerator<> (for semanatic search) and IChatClient (for chatbot interaction) where demoed at .NET Conf to show switching between OLlama and OpenAI. Pipelines where shown (similar to langchain) with setting rate limiting chatbot prompting in the demo. Pipeline functions act as middleware on the model with behaviours described by metadata, inputs and outputs for specific scenarios. RAG was also shown combining semantic search in IEmbeddingGenerator<> with IChatClient to search the .NET git repo issues with minimal code setup to search and summarise information based on a chatbot question. Image content summarization and structured data output to summarize traffic states and vehicle count data was quite impressive.

Check out Steve Sanderson’s demo presentation (YouTube) of the these Microsoft.Extensions.AI features.

C# 13

  • Method params can now use any collection types not just arrays
  • [OverloadResolutionPriority()] attribute for class constructors (all default to 0) and can use negatives (this has been utilized in lots of .NET 9 library code)
  • New (more efficient) Lock type to use with lock()
  • Auto props field to access the generated private prop (In C# 13 preview). public string Data { get { return field; } set { field = value; } }

.NET 9 Framework / Libraries

  • BinaryFormater has been removed, which has been a long time coming. It’s still possible to load in but the migration guide is being pushed and it’s a no-brainer for code security.
  • Task.WhenEach() to return an async enumerable to respond on a task finishing instead of waiting on a Task.WhenAll()
  • Base64Url class for helpful and optimized conversions usually done in Convert class
  • IEnumerable.Index() to return a tuple of (index, item) to use in loops
  • JsonSchemaExporter to get generate schema from C# type
  • JsonElement.DeepEquals() deep equality comparer (very handy)
  • JSON nullable enforcement via RespectNullableAnnotations setting will throw errors when null value provided for prop that is not nullable
  • Debug.Assert() improved to show the failed assert rule in output
  • Feature switching for libraries and support to remove unused code on trimming / native AOT compile (different to Microsoft.FeatureManagement). Theser are under System.Diagnostics.CodeAnalysis FeatureSwtichDefinitionAttribute and FeatureGuardAttribute

Check out my gist to try out most of these features

.NET 9 SDK

Performance seemed to be the main focus on the SDK

  • GC memory improvements, higher requests per sec and 93% lower mem test in benchmarks, can configure to use legacy GC if need be
  • RyuJIT jit compiler improvements
  • Securty – Control-flow enforcement enabled by default for app host but not dotnet run (due to slight perf cost) to prevent windows return oriented code attacks
  • .net install feature to allow multiple apps to use one apps self contained private runtime (instead of global runtime install or priv runtime for each app

Azure and .NET 9

Paul Yuknewicz has some handy gists from his .NET conf presentation of integrating Azure AI with functions for chatbots with memory and durable function chaining for document analysis

.NET Aspire 9

.NET Aspire has also had a lot of attention from customer feedback and is looking much more mature and feature rich.

  • Now supports Azure functions (Aspire.Hosting.Azure.Functions preview) but only for some bindings/outputs (http, blob, storagequeue, servicebus, eventhub), a key benefit is having full end to end tracing by a function invocationid when you have many functions!Browser App telemetry now shown in dashboard
  • AppHost WaitFor() to wait on dependant resources using standard healthchecks
  • Can now set persistent containers (a big win for the dev env when there are dependencies that take a long time to start up)
  • Azure OpenAI client integration (preview)
  • PublishAsAzureContainerApp() with IaC style environment definitions for deployment and ConfigureInfrastructure() to setup

Checkout the Azure Functions Aspire Sample and there’s more improvements covered in Whats new in .Net Aspire 9

Visual Studio 2022 17.12

There are quite few helpful improvements but I found no massive leaps

  • Improved Code search
  • Find results panel now has a Refresh button!
  • git permalink in context menu
  • Improved .http file functionality
  • Github co-pilot improvements

MSLearn – VS 2022 17.12 release notes

Links

My gist of whats handy in C# 13 / .net 9

.NET Conf Presentations (YouTube)

MSLearn – What’s new in .Net 9

MSLearn – Whats new in .Net Aspire 9

MSLearn – Azure Functions in Aspire

Azure Functions Aspire Sample

Helpful, in-depth blog post of .net 9 improvements and code samples

In-depth MS blog post on System.Text.Json improvements

Leave a Reply

Your email address will not be published. Required fields are marked *