.NET 11 Preview 2 includes new .NET Libraries features & enhancements:
- Generic GetTypeInfo for System.Text.Json
- Tar archive format selection
- Matrix4x4.GetDeterminant ~15% faster
.NET Libraries updates in .NET 11:
- What's new in .NET 11 documentation
A common pattern when working with System.Text.Json type metadata is to retrieve a JsonTypeInfo<T> from JsonSerializerOptions, which previously required a manual downcast from the non-generic GetTypeInfo(Type) method (dotnet/runtime#118468). New generic GetTypeInfo<T>() and TryGetTypeInfo<T>() methods on JsonSerializerOptions eliminate this cast and return strongly-typed metadata directly (dotnet/runtime#123940).
// Before: manual downcast required
JsonTypeInfo<MyType> info = (JsonTypeInfo<MyType>)options.GetTypeInfo(typeof(MyType));
// After: generic method returns the right type directly
JsonTypeInfo<MyType> info = options.GetTypeInfo<MyType>();
// TryGetTypeInfo variant for cases where the type may not be registered
if (options.TryGetTypeInfo<MyType>(out JsonTypeInfo<MyType>? typeInfo))
{
// Use typeInfo
}This is particularly useful when working with source generation, NativeAOT, and polymorphic serialization scenarios where type metadata access is common.
New overloads on TarFile.CreateFromDirectory accept a TarEntryFormat parameter, giving you direct control over the archive format (dotnet/runtime#123407). Previously, CreateFromDirectory always produced Pax archives. The new overloads support all four tar formats — Pax, Ustar, GNU, and V7 — for compatibility with specific tools and environments (dotnet/runtime#121819).
// Create a GNU format tar archive for Linux compatibility
TarFile.CreateFromDirectory("/source/dir", "/dest/archive.tar",
includeBaseDirectory: true, TarEntryFormat.Gnu);
// Create a Ustar format archive for broader compatibility
TarFile.CreateFromDirectory("/source/dir", outputStream,
includeBaseDirectory: false, TarEntryFormat.Ustar);
// Async version
await TarFile.CreateFromDirectoryAsync("/source/dir", "/dest/archive.tar",
includeBaseDirectory: true, TarEntryFormat.Pax, cancellationToken);Thank you @kasperk81 for this contribution!
Matrix4x4.GetDeterminant now uses an SSE-vectorized implementation, improving performance by approximately 15% (dotnet/runtime#123954).
| Scenario | Before | After | Improvement |
|---|---|---|---|
GetDeterminantBenchmark |
3.487 ns | 2.971 ns | ~15% faster |
Thank you @alexcovington for this contribution!
This release includes bug fixes and quality improvements across several areas:
- System.Collections
- Fixed integer overflow in
ImmutableArrayrange validation (dotnet/runtime#124042)
- Fixed integer overflow in
- System.IO.Compression
- Fixed
ZipArchiveEntry.ExtractToFilepreserving files on extraction failure withoverwrite: true(dotnet/runtime#123991)
- Fixed
- System.Linq
- Fixed
Append/PrependGetCountoverflow to correctly throwOverflowException(dotnet/runtime#123821)
- Fixed
- System.Net.Http
- Fixed authenticated proxy credential handling for proxies that require proactive
Proxy-Authorizationheaders (dotnet/runtime#123328, reported by @ptarjan) - Fixed edge-case non-ASCII host handling in HTTP logic (dotnet/runtime#123934)
- Fixed authenticated proxy credential handling for proxies that require proactive
- System.Numerics
- Fixed
Vector2/Vector3EqualsAnyand related methods returning incorrect results due to hidden padding elements (dotnet/runtime#123594, dotnet/runtime#123586) - Fixed missing early returns in
TensorPrimitives.Roundcausing double-rounding (dotnet/runtime#124280)
- Fixed
- System.Reflection
- Fixed
MetadataLoadContextreturning internal array types instead ofType[]from several methods (dotnet/runtime#124251, reported by @smdn)
- Fixed
- System.Runtime
- Fixed vectorization of
Ascii.Equalsfor input lengths 8–15 (dotnet/runtime#123115)
- Fixed vectorization of
Thank you contributors! ❤️