What's new in ASP.NET Core in .NET 11 Preview 6#37334
What's new in ASP.NET Core in .NET 11 Preview 6#37334wadepickett with Copilot wants to merge 3 commits into
Conversation
|
@tdykstra and @guardrex, |
|
@wadepickett ... Thanks!👍 Illona has a PR up, and I have one with only the Blazor C# union bits on it. I'll check next week to see what else Blazor needs. I'll review this Monday morning (without commits from me) to assist @tdykstra with the approval he'll need. |
Edit pass. Co-authored-by: Wade Pickett <wpickett@microsoft.com>
guardrex
left a comment
There was a problem hiding this comment.
Approving with a handful of NIT suggestions.
|
|
||
| <!-- TODO: Update `AsyncValidationAttribute`, `IAsyncValidatableObject`, and `Validator.ValidateObjectAsync` to <xref:> once API docs are published. --> | ||
|
|
||
| Asynchronous validation lets a validation rule do real work, such as a database lookup or a remote API call, without blocking a thread. A model implements `IAsyncValidatableObject` and returns validation results as an `IAsyncEnumerable<ValidationResult>`. Because `IAsyncValidatableObject` extends `IValidatableObject`, also implement the synchronous `Validate` method. When a type validates asynchronously only, throw from `Validate` so it isn't silently validated through the synchronous APIs: |
There was a problem hiding this comment.
| Asynchronous validation lets a validation rule do real work, such as a database lookup or a remote API call, without blocking a thread. A model implements `IAsyncValidatableObject` and returns validation results as an `IAsyncEnumerable<ValidationResult>`. Because `IAsyncValidatableObject` extends `IValidatableObject`, also implement the synchronous `Validate` method. When a type validates asynchronously only, throw from `Validate` so it isn't silently validated through the synchronous APIs: | |
| Asynchronous validation lets a validation rule do real work, such as a database lookup or a remote API call, without blocking a thread. A model implements `IAsyncValidatableObject` and returns validation results as an `IAsyncEnumerable<ValidationResult`. Because `IAsyncValidatableObject` extends `IValidatableObject`, also implement the synchronous `Validate` method. When a type validates asynchronously only, throw from `Validate` so it isn't silently validated through the synchronous APIs: |
| [EnumeratorCancellation] CancellationToken cancellationToken = default) | ||
| { | ||
| var rooms = context.GetRequiredService<IRoomService>(); | ||
| if (!await rooms.HasAvailabilityAsync(Date, cancellationToken)) |
There was a problem hiding this comment.
Optional; but AFAIK (and what I've been doing in the Blazor node and samples), framework coding calls for a line between the start of an if expression and a preceding code line.
| if (!await rooms.HasAvailabilityAsync(Date, cancellationToken)) | |
| if (!await rooms.HasAvailabilityAsync(Date, cancellationToken)) |
| ### C# union types | ||
|
|
||
| ASP.NET Core supports [C# union types](/dotnet/csharp/whats-new/csharp-14#union-types) (new in .NET 11) anywhere [`System.Text.Json`](/dotnet/standard/serialization/system-text-json/overview) is used: JSON request and response bodies in Minimal APIs and MVC, SignalR's `JsonHubProtocol`, Blazor JavaScript interop, persistent component state, and prerendered component parameters. | ||
| C# union types are a preview language feature in .NET 11 (see the [C# release notes](/dotnet/csharp/whats-new/csharp-14#union-types)), and [`System.Text.Json`](/dotnet/standard/serialization/system-text-json/overview) serializes them natively. Because ASP.NET Core uses `System.Text.Json` for JSON, union types work as JSON request bodies and return types throughout the stack with no ASP.NET-specific configuration: |
There was a problem hiding this comment.
You could also place the C# language reference cross-link here as well, but this is What's New, so perhaps it's best to leave it as-is. I went through on the Blazor PR and updated all of the non-What's New references to use the reference doc, so we won't be saddled with pointing devs to a What's New language feature article in reference content when the language reference article exists. Here's the link in case you want to see or use it ...
https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/union
| Union types aren't supported for non-body binding sources such as route values, query strings, headers, and form fields. No newline at end of file | ||
| For OpenAPI, an endpoint that returns a union is described with an `anyOf` schema listing each case type. Unlike polymorphic types, union cases don't carry a `$type` discriminator, so a case such as `Dog` reuses the standalone `#/components/schemas/Dog` component instead of a duplicated, prefixed one. ApiExplorer detects a union through `JsonTypeInfoKind.Union`, so the schema also flows through to Swashbuckle and NSwag. | ||
|
|
||
| A few limits apply. Only JSON request bodies and responses are supported — binding a union from the query string, route values, headers, or form fields isn't yet available. When multiple cases serialize to the same JSON shape, disambiguate them with a `[JsonUnion]` classifier. SignalR unions require the JSON hub protocol; the MessagePack and Newtonsoft.Json protocols don't support unions. No newline at end of file |
There was a problem hiding this comment.
| A few limits apply. Only JSON request bodies and responses are supported — binding a union from the query string, route values, headers, or form fields isn't yet available. When multiple cases serialize to the same JSON shape, disambiguate them with a `[JsonUnion]` classifier. SignalR unions require the JSON hub protocol; the MessagePack and Newtonsoft.Json protocols don't support unions. | |
| A few limits apply. Only JSON request bodies and responses are supported—binding a union from the query string, route values, headers, or form fields isn't yet available. When multiple cases serialize to the same JSON shape, disambiguate them with a `[JsonUnion]` classifier. SignalR unions require the JSON hub protocol; the MessagePack and `Newtonsoft.Json` protocols don't support unions. |
| @@ -0,0 +1,12 @@ | |||
| ### OpenAPI 3.2 by default | |||
|
|
|||
| Generated OpenAPI documents now target OpenAPI 3.2 by default. Documents continue to generate as before; set the document version explicitly if you need to target an earlier version for tooling that hasn't adopted 3.2 yet. | |||
There was a problem hiding this comment.
| Generated OpenAPI documents now target OpenAPI 3.2 by default. Documents continue to generate as before; set the document version explicitly if you need to target an earlier version for tooling that hasn't adopted 3.2 yet. | |
| Generated OpenAPI documents now target OpenAPI 3.2 by default. Documents continue to generate as before. Set the document version explicitly if you need to target an earlier version for tooling that hasn't adopted 3.2 yet. |
|
|
||
| <!-- TODO: Update `[ShortCircuit]` to <xref:> once API docs are published. --> | ||
|
|
||
| Short-circuiting is useful for endpoints that don't need authentication, CORS, or other middleware — for example a health check or a robots.txt response — and it avoids the cost of running that middleware. The endpoint still runs and produces its response. Pass an optional status code, such as `[ShortCircuit(404)]`, to set the response status code. |
There was a problem hiding this comment.
I still need to understand if the repo's convention for code-fencing all filenames and paths remains in effect after the "freshness" pass.
| Short-circuiting is useful for endpoints that don't need authentication, CORS, or other middleware — for example a health check or a robots.txt response — and it avoids the cost of running that middleware. The endpoint still runs and produces its response. Pass an optional status code, such as `[ShortCircuit(404)]`, to set the response status code. | |
| Short-circuiting is useful for endpoints that don't need authentication, CORS, or other middleware—for example a health check or a `robots.txt` response—and it avoids the cost of running that middleware. The endpoint still runs and produces its response. Pass an optional status code, such as `[ShortCircuit(404)]`, to set the response status code. |
Adds Preview 6 content to the cumulative "What's new in ASP.NET Core in .NET 11" article, generated from the dotnet/core release notes (dotnet/core#10456) via the
whats-new-from-release-notesagent.Note on parameters: The issue body listed
PREVIEW = preview5, but the referenced source PR and the issue title are both Preview 6. Processed Preview 6 accordingly.New include files
async-validation-minimal-apis-preview-6.md(IAsyncValidatableObject,AsyncValidationAttribute,Validator.ValidateObjectAsync),short-circuit-endpoints-attribute-preview-6.md([ShortCircuit])openapi-3-2-default-preview-6.md(documents now target 3.2 by default)signalr-authentication-refresh-preview-6.md(token refresh without reconnect),signalr-cancel-hub-invocations-preview-6.md(client-side cancellation of non-streaming invocations)Updated files
csharp-unions-preview-6.md— expanded to reflect the grown source: unions now span Minimal APIs, MVC/Razor Pages, SignalR JSON hub protocol, and Blazor, plus OpenAPIanyOfschema behavior and non-body binding limits.aspnetcore-11.md— added[!INCLUDE]directives in the mapped sections; bumpedms.dateto07/10/2026; Breaking changes section left intact.Excluded (per content rules)
@Youssef1313,@Porozhniakov) are preserved within their feature includes.Conventions
Includes use H3 headings, no front matter,
-preview-6suffixes, relative Learn links, and present-tense phrasing. Verified<xref:>IDs are used where docs exist; brand-new Preview 6 APIs without published docs carry<!-- TODO: Update to <xref:> ... -->markers for later conversion.Internal previews