Repository navigation
[Blazor] Support Aspire Dashboard on Native AOT - #68307
Merged
Merged
Conversation
javiercn
force-pushed
the
javiercn-minimal-aspire-dashboard-aot
branch
from
August 11, 2026 10:30
8949214 to
679803c
Compare
javiercn
force-pushed
the
javiercn-minimal-aspire-dashboard-aot
branch
from
August 11, 2026 16:57
4072eda to
3801d62
Compare
javiercn
marked this pull request as ready for review
August 12, 2026 08:59
Contributor
There was a problem hiding this comment.
Pull request overview
Enables Blazor Interactive Server scenarios (notably the Aspire Dashboard) to run under Native AOT by supplying source-generated System.Text.Json metadata for framework-owned payloads, and by introducing an experimental application extension point (CircuitOptions.JsonTypeInfoResolvers) to flow app-provided IJsonTypeInfoResolver instances into circuit JSON serialization (JS interop + protected browser storage).
Changes:
- Add
CircuitOptions.JsonTypeInfoResolvers(experimental) and compose resolvers intoRemoteJSRuntimeand protected browser storage serializer options. - Introduce/extend source-generated JSON contexts for fixed framework protocols (server component markers/operations, web renderer interop args, prerender state, JS initializer manifest, persistent services registry DTOs).
- Add Native AOT/dynamic-code-safe fallbacks for expression-based model access and enum binding, plus focused unit tests for the new JSON/interop behaviors.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/Components/ServerComponentSerializer.cs | Serialize ServerComponent using JsonTypeInfo from configured options. |
| src/Shared/Components/ServerComponentSerializationSettings.cs | Build JsonSerializerOptions with generated context + optional reflection resolver; add ServerComponentJsonContext. |
| src/Shared/Components/PrerenderComponentApplicationStore.cs | Serialize persisted prerender state via source-generated context. |
| src/JSInterop/Microsoft.JSInterop/test/Infrastructure/DotNetObjectReferenceJsonConverterTest.cs | Add tests asserting runtime provides converter-backed JsonTypeInfo (including IJSVoidResult). |
| src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs | Add JS interop IJsonTypeInfoResolver and optional reflection resolver; refactor pending calls. |
| src/JSInterop/Microsoft.JSInterop/src/Infrastructure/PendingAsyncCall.cs | New typed pending-call implementation that completes via JsonTypeInfo. |
| src/JSInterop/Microsoft.JSInterop/src/Infrastructure/JSInteropJsonTypeInfoResolver.cs | New resolver that supplies converter-backed metadata (and null-only IJSVoidResult). |
| src/JSInterop/Microsoft.JSInterop/src/Infrastructure/IPendingAsyncCall.cs | New pending-call abstraction for result completion/failure/cancellation. |
| src/Components/Web/test/Rendering/WebRendererJsonResolverTest.cs | New test validating WebRenderer inserts framework interop JSON contracts and invokes expected JS identifier. |
| src/Components/Web/src/WebRenderer.cs | Ensure framework serializer context is inserted into options; add generated contracts for interop argument types. |
| src/Components/Web/src/WebEventData/WebEventData.cs | Avoid raw-text deserialization; use GetTypeInfo and special-case EventArgs. |
| src/Components/Shared/src/JsonSerializerOptionsProvider.cs | Build shared JSON options and add optional reflection resolver when enabled by default. |
| src/Components/Shared/src/ExpressionFormatting/ExpressionFormatter.cs | Add dynamic-code-safe member evaluation path for captured value formatting. |
| src/Components/Server/test/ProtectedBrowserStorageTest.cs | Add test for source-generated options round-tripping a parameterized type; extend coverage. |
| src/Components/Server/test/PrerenderComponentApplicationStoreTest.cs | New test covering prerender store persistence roundtrip. |
| src/Components/Server/test/Circuits/CircuitOptionsJavaScriptInitializersConfigurationTest.cs | New test validating JS initializer manifest parsing. |
| src/Components/Server/src/PublicAPI.Unshipped.txt | Add public API entry for CircuitOptions.JsonTypeInfoResolvers. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedSessionStorage.cs | Add internal ctor overload accepting JsonSerializerOptions. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedLocalStorage.cs | Add internal ctor overload accepting JsonSerializerOptions. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorageJsonSerializerOptions.cs | New scoped options composer applying CircuitOptions.JsonTypeInfoResolvers. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs | Use JsonTypeInfo for (de)serialization; accept injected serializer options. |
| src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs | Register composed serializer options and wire them into protected storage services. |
| src/Components/Server/src/Circuits/ServerComponentJsonContext.Server.cs | Extend ServerComponentJsonContext with server-only root operation batch contracts. |
| src/Components/Server/src/Circuits/ServerComponentDeserializer.cs | Deserialize using JsonTypeInfo for markers/components/root operations. |
| src/Components/Server/src/Circuits/RemoteNavigationManager.cs | Serialize renderer ID as int to avoid enum metadata requirements. |
| src/Components/Server/src/Circuits/RemoteNavigationInterception.cs | Serialize renderer ID as int to avoid enum metadata requirements. |
| src/Components/Server/src/Circuits/RemoteJSRuntime.cs | Insert application-provided resolvers into JsonSerializerOptions.TypeInfoResolverChain. |
| src/Components/Server/src/Circuits/CircuitOptionsJavaScriptInitializersConfiguration.cs | Source-generate manifest parsing for JS initializer modules list. |
| src/Components/Server/src/CircuitOptions.cs | Add experimental JsonTypeInfoResolvers extension point. |
| src/Components/Forms/src/FieldIdentifier.cs | Add dynamic-code-safe expression evaluation fallback for model discovery. |
| src/Components/Components/test/PersistentState/PersistentServicesRegistryTest.cs | Add tests for empty registry persistence + legacy wire-format restore. |
| src/Components/Components/test/BindConverterTest.cs | Add tests for dynamic-code-safe enum conversion parity. |
| src/Components/Components/src/PersistentState/PersistentServicesRegistry.cs | Persist stable DTO array via generated context; restore via bytes while keeping legacy compatibility. |
| src/Components/Components/src/BindConverter.cs | Add dynamic-code-safe enum parsing delegates when dynamic code isn’t supported. |
Suppressed comments (1)
src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs:141
- Protecting a null value currently forces a JsonTypeInfo lookup for typeof(object). When reflection-based serialization is disabled, this can require an application-provided resolver even though the correct JSON payload is always just the literal "null". Since null storage is already a supported scenario (tests expect "null"), special-case null to avoid requiring type metadata/resolvers for this case.
private string Protect(string purpose, object value)
{
var typeInfo = _serializerOptions.GetTypeInfo(value?.GetType() ?? typeof(object));
var json = JsonSerializer.Serialize(value, typeInfo);
var protector = GetOrCreateCachedProtector(purpose);
return protector.Protect(json);
}
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
maraf
approved these changes
Aug 12, 2026
Keep reflection as the compatibility path while generating fixed server marker contracts, retaining outbound JS result types, and allowing apps to supply JS interop JSON metadata. Co-authored-by: Copilot App <[email protected]>
Generate the fixed root-operation JSON contracts used by blazor.web.js and remove the form-binding-only change from this experiment. Co-authored-by: Copilot App <[email protected]>
Compose application JSON contracts into protected browser storage and generate the fixed NavigationOptions contract used by Server navigation. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Use generated framework contracts for modules and persistent state, and provide converter-backed JS interop metadata without reflection serialization. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 19dd876d-31dc-41b4-a53b-aa2299746d2a
Validate framework JSON metadata through the configured JsonSerializerOptions resolver chain instead of invoking individual resolvers directly. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 22ea1330-4e21-4ac3-ab94-eafa89a2efc6
Exercise reflection-enabled Interactive Server paths used by the Aspire Dashboard with the current Components Testing Native AOT harness. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 19dd876d-31dc-41b4-a53b-aa2299746d2a
javiercn
force-pushed
the
javiercn-minimal-aspire-dashboard-aot
branch
from
August 12, 2026 12:51
3801d62 to
e7ec894
Compare
3 tasks
Keep ordinary restores off unpublished shared-framework runtime packs, restore the Native AOT fixture with matching harness properties, and tolerate JS interop completion races after cancellation. Co-authored-by: Copilot App <[email protected]>
Root only the application assembly and keep the reflection-enabled fixture's reachable trim and AOT diagnostics as warnings under CI. Co-authored-by: Copilot App <[email protected]>
Allow known NU1510 package-pruning diagnostics from existing framework projects during the Native AOT fixture restore without suppressing them. Co-authored-by: Copilot App <[email protected]>
Let the app's RuntimeIdentifiers prepare RID assets without imposing a RID on analyzer projects, and flow known NU1510 pruning diagnostics across referenced restores. Co-authored-by: Copilot App <[email protected]>
Restore only the fixture root with AOT properties so parallel CI builds do not rewrite shared transitive project assets. Co-authored-by: Copilot App <[email protected]>
maraf
approved these changes
Aug 13, 2026
4 tasks done
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Enables the Aspire Dashboard to run as an Interactive Server application under Native AOT using narrow runtime fixes rather than the broader component-metadata/source-generator architecture. Reflection remains enabled for component discovery and activation; this PR does not change Blazor's trimming requirements or claim reflection-disabled/full-trimming support.
The live diff contains 61 framework and generic test files (+1843/-62). It contains no Aspire Dashboard source, FluentUI/Plotly/OTLP code, package pins, or vendored fixture artifacts.
Design
The only new public contract lets an Interactive Server application compose source-generated JSON contexts into the circuit's
JsonSerializerOptions:Application resolvers run in registration order before the reflection fallback and are shared by JS interop and protected browser storage. All other added metadata is internal and fixed: server component markers/root operations, web renderer arguments, prerender state, the JS initializer manifest, and converter-backed framework JS interop values.
Interactive forms retain their normal JIT fast paths, but avoid expression compilation and runtime generic enum closure when dynamic code is unavailable. The fallback evaluates the existing expression tree through field/property/index access, which covers the Dashboard's nested interactive edit models.
Explicitly excluded: source-generated component metadata/provider tables, generated JS-invokable dispatch, bindable graph generation, arbitrary third-party component support, reflection-disabled strict mode, array-valued
InputSelect<T[]>, and SSR HTTP form mapping.Durable Native AOT browser coverage
This PR now commits a generic
NativeAotTestAppand MTP/Playwright suite built on the currentMicrosoft.AspNetCore.Components.TestingE2ENativeAotharness. It does not copy the superseded harness from #68291 and has no Dashboard or FluentUI dependency.The published
win-x64Native AOT executable passes 8/8 scenarios:InteractiveShell_RendersAndHandlesDynamicUi: parameters, cascading values, injection, callbacks, conditional rendering, andDynamicComponentmenu/dialog/tab-like UI.Forms_BindValidateAndSubmitDashboardInputMatrix: text, number, checkbox, enum and nullable enum, nested property, list index, failed validation, and successful interactive submit.JsInterop_ResolversAndCustomEventsRoundTrip: resolver ordering, app POCOs,DotNetObjectReference,ElementReference, and custom event args.ProtectedStorage_RestoresAcrossReload: an app source-generated contract with a custom converter across a browser reload/new circuit.PersistentState_RestoresAcrossPrerender: app state and a custom persistent-state serializer across prerender-to-circuit restoration.Virtualize_ScrollsAndLoadsRows:Virtualize<T>, float JS payloads, incremental rendering, and test-owned expression getter/setter delegates under Native AOT.InputFile_StreamsAndSubmitsFile: real browser selection, stream read, exact name/content/length, submit, and rerender.EnhancedNavigation_QueryAndHistoryRemainInteractive: typedint/boolquery values, enhanced link navigation, back/forward, and continued circuit interaction.Every scenario asserts a rendered
RuntimeFeature.IsDynamicCodeSupported == falsesignal, a live Interactive Server circuit, concrete post-interaction state, hidden#blazor-error-ui, and no browser console, page, WebSocket, circuit, or JSON serialization errors.Actual circuit pause/resume is not committed because the current canonical Components harness exposes no deterministic pause/resume driver for this fixture. The existing local Dashboard acceptance experiment proved
Blazor.pauseCircuit()/resumeCircuit()can return true, but Dashboard resource selection is not opted into persisted state.Validation
The richer uncommitted Dashboard acceptance suite exercised populated resources/list/details/graph; dynamic resource-command forms and file upload; structured correlated OTLP logs; a two-service parent/child trace with span hierarchy, status, events, links, attributes and related logs; sum/gauge/histogram metrics with concrete values and Plotly rendering; console logs; protected/unprotected storage reload; and direct
MaxItemCountHelperinterpreter instrumentation. Those Dashboard/FluentUI/OTLP assets remain deliberately outside this PR.Native publish continues to report expected trim/AOT diagnostics from reflection-rooted Blazor paths. The test executable suppresses existing entry-point/static-analysis annotations only where its complete application assembly is explicitly rooted; no product trimming annotations, defaults, or requirements are changed.