You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(journaling): resolve trimming and NativeAOT warnings - #11513
With the trim, AOT, and single-file analyzers enabled (the repository's compatibility analyzer audit), the journaling and durable jobs code on main reports 14 warnings:
JournaledPersistentState<T> creates default state through the serializer's IActivatorProvider, which is the pattern StateStorageBridge<TState> uses for classic IPersistentState<T>. Annotating T instead would be a false fix. The type is registered as an open-generic implementation of the unannotated IPersistentState<>, and DI's VerifyOpenGenericServiceTrimmability check (on by default in trimmed apps) rejects implementation generic parameters whose annotations the service type lacks. As a result, journaled persistent state now matches classic persistent state for state types without a parameterless constructor (for example, positional records). Before this change, those types threw MissingMethodException.
CodecProvider.GetActivator<T>() returns a DefaultNullableActivator<T> for Nullable<T>, which creates null, the same result as Activator.CreateInstance<T?>(). Previously it selected DefaultValueTypeActivator<T?>, which violates that type's struct constraint, so both journaled and classic IPersistentState<int?> failed to construct. Like the other default activators, it is rooted with DynamicDependency, and the serialization trimmed smoke covers all three default activators.
JSON journal codecs constructed with options: null keep using JsonSerializerOptions.Default, behind one accessor with a scoped suppression. Trimmed and NativeAOT publishing disables System.Text.Json reflection. With reflection disabled, JsonSerializerOptions.Default uses an empty type-info resolver, so missing metadata surfaces as the existing configuration error.
Azure Table journal metadata uses a source-generated JsonSerializerContext. The stored JSON is unchanged; a new test pins the wire format.
AzureTableStorageJournalingProviderBuilder reads each configurable member of AzureTableJournalStorageOptions and its nested ClientOptions (EnableTenantDiscovery, Retry, Diagnostics) with ConfigurationBinder.GetValue. On net10.0, the project enables the configuration-binding source generator, which binds these values without reflection. Like Bind, invalid values throw InvalidOperationException. The generator can't bind these four types as objects: they expose client instances, pipeline policies and delegates, and the Azure option types lack public constructors. For them it reports SYSLIB1100/SYSLIB1101, which #pragma, [SuppressMessage] and .editorconfig can't suppress at a call site. When the ClientOptions section is present, the builder creates TableClientOptions if it isn't already set. net8.0 uses the reflection-based binder for the same calls.
DurableJobsEvents writes every payload through one private helper. The helper constrains TEvent to the event base type and annotates it with PublicFields | PublicProperties, which is a superset of what DiagnosticSource.Write<T> requires. A single justified IL2026 suppression covers it. DiagnosticSource.Write is unconditionally [RequiresUnreferencedCode], so keeping DiagnosticListener requires this one suppression.
GetJournalStorageOptions<TOptions> carries the PublicParameterlessConstructor requirement through to IOptions<TOptions>/IOptionsMonitor<TOptions>.
Regression gate: each of the six project files enables the trim, AOT, and single-file analyzers on net10.0. With TreatWarningsAsErrors, any new warning fails the build.
Rationale
These projects aren't marked IsAotCompatible. That property also stamps the assemblies as trimmable, so ILLink would trim them in the default partial mode. Their required Orleans.Core/Orleans.Runtime dependencies still carry unresolved trimming and AOT warnings, and the NativeAOT smoke scenarios don't exercise journaling. Enabling the analyzers stops regressions in this code without claiming end-to-end AOT support.
No public API changes: every changed member is internal or private, and Release pack package validation passes for the changed packages.
The current-main baseline is commit 1d3361287c and uses the same reviewed coverage matrix.
Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.
The comparison remains report-only while normal line and branch variance is calibrated.
Replacing Bind(options) with explicit parsing drops the ClientOptions subtree. If an earlier options callback initializes ClientOptions and calls ConfigureTableServiceClient, configuration such as Provider:ClientOptions:Retry:MaxRetries previously updated that instance. With no connection setting or service key overriding the callback, the provider still creates its client from those options, but now silently ignores the configured retry limit. Preserve trim-safe parsing of previously supported client settings and add a regression test combining programmatic client setup with configuration overrides.
Replacing Bind(options) with these scalar reads silently drops nested ClientOptions configuration. When an application preconfigures ClientOptions and calls ConfigureTableServiceClient(connectionString), a setting such as Provider:ClientOptions:Retry:MaxRetries previously updated that instance before client creation; it is now ignored. The deferred factory still consumes ClientOptions (AzureTableJournalStorageOptions.cs:237–240), so existing retry settings no longer take effect. Preserve the previously supported nested settings through trim-safe binding, and add a regression test with a preconfigured client-options instance and factory.
Addressed the "Preserve nested ClientOptions configuration" finding from the review summary in 28e6064.
It was valid. I checked the reflection-based Bind that main uses: with ClientOptions preconfigured, it applied ClientOptions:Retry:*, ClientOptions:Diagnostics:* and ClientOptions:EnableTenantDiscovery to that instance. With ClientOptions null, it threw because TableClientOptions can't be constructed through binding.
The builder now reads those settings explicitly with GetValue, which the configuration-binding generator intercepts. That means no trimming or AOT warnings and no SYSLIB diagnostics. The generator can't BindRetryOptions or DiagnosticsOptions, even into an existing instance, because they have no public constructors (SYSLIB1100). When the ClientOptions section is present and ClientOptions is null, the builder now creates a TableClientOptions instead of throwing. Invalid values still throw, as Bind did.
New tests in AzureTableStorageJournalingProviderBuilderTests cover both cases, preconfigured and null ClientOptions, through a ConfigureTableServiceClient factory. They also cover an invalid retry value, and confirm that ClientOptions stays unset when the section is absent.
Remove the trimming and NativeAOT analyzer warnings from Orleans.Journaling, its storage providers, and Orleans.DurableJobs, and enable the trim, AOT, and single-file analyzers for these projects on net10.0 so regressions fail the build.
- JournaledPersistentState creates default state with the serializer's IActivatorProvider, matching StateStorageBridge.
- JSON journal codecs use JsonSerializerOptions.Default only when System.Text.Json reflection is enabled.
- Azure Table journal metadata uses a source-generated JsonSerializerContext.
- The Azure Table journaling provider builder reads operational options explicitly instead of using reflection-based ConfigurationBinder.Bind.
- DurableJobsEvents writes payloads through a single annotated DiagnosticListener helper.
- GetJournalStorageOptions flows the options constructor requirement to IOptions/IOptionsMonitor.
- Return null from the default activator for Nullable<T>; it previously violated DefaultValueTypeActivator's struct constraint, breaking nullable journaled and classic persistent state.
- Throw when an Azure Table journaling option is configured with an invalid value, matching ConfigurationBinder.Bind.
- Use JsonSerializerOptions.Default directly; with reflection disabled it uses an empty resolver and reports missing metadata.
…hen trimming
Root DefaultNullableActivator<> with DynamicDependency like the other default activators, and cover the default nullable, value-type, and reference-type activators in the serialization trimmed smoke.
…urationBinder.GetValue
Replace the private TryParseValue helper with ConfigurationBinder.GetValue, which throws for invalid values like Bind, and enable the configuration-binding source generator so the primitive GetValue calls stay trim- and AOT-safe.
…uration
Bind previously applied ClientOptions:Retry, ClientOptions:Diagnostics, and ClientOptions:EnableTenantDiscovery to the configured TableClientOptions, which clients created through ConfigureTableServiceClient read. Restore those settings with explicit GetValue reads, which the configuration-binding generator supports; it cannot bind RetryOptions or DiagnosticsOptions as objects because they lack public constructors. TableClientOptions is created when the section is present instead of failing as Bind did.
…nfiguration-binding generator
On net10.0, the configuration-binding source generator binds AzureTableJournalStorageOptions, including nested ClientOptions retry and diagnostics settings, without reflection. Create ClientOptions before binding because TableClientOptions has no bindable constructor, and suppress SYSLIB1100/SYSLIB1101 for the client, pipeline, and delegate members configured in code. net8.0 keeps the reflection-based binder.
…ator cannot bind
AzureTableJournalStorageOptions, TableClientOptions, RetryOptions, and DiagnosticsOptions expose client instances, pipeline policies, delegates, or lack public constructors, so the configuration-binding generator reports SYSLIB1100/SYSLIB1101 for them, and those diagnostics cannot be suppressed per call site. Read their configurable members individually with GetValue, which the generator binds, and remove the project-wide SYSLIB1100/SYSLIB1101 suppression.
Move the net10.0 trim, AOT, and single-file analyzer settings from per-project conditions in src/Directory.Build.props into the six journaling and durable jobs project files.
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 18, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 18, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Oct 31, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond
added a commit
to ReubenBond/orleans
that referenced
this pull request
Nov 11, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
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
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.
Problem
With the trim, AOT, and single-file analyzers enabled (the repository's compatibility analyzer audit), the journaling and durable jobs code on
mainreports 14 warnings:JsonSerializerOptions.Default; IL2091Activator.CreateInstance<T>(); IL2091 ×2IOptions<TOptions>/IOptionsMonitor<TOptions>DiagnosticSource.Write<T>JsonSerializer; IL2026/IL3050ConfigurationBinder.BindSolution
JournaledPersistentState<T>creates default state through the serializer'sIActivatorProvider, which is the patternStateStorageBridge<TState>uses for classicIPersistentState<T>. AnnotatingTinstead would be a false fix. The type is registered as an open-generic implementation of the unannotatedIPersistentState<>, and DI'sVerifyOpenGenericServiceTrimmabilitycheck (on by default in trimmed apps) rejects implementation generic parameters whose annotations the service type lacks. As a result, journaled persistent state now matches classic persistent state for state types without a parameterless constructor (for example, positional records). Before this change, those types threwMissingMethodException.CodecProvider.GetActivator<T>()returns aDefaultNullableActivator<T>forNullable<T>, which createsnull, the same result asActivator.CreateInstance<T?>(). Previously it selectedDefaultValueTypeActivator<T?>, which violates that type'sstructconstraint, so both journaled and classicIPersistentState<int?>failed to construct. Like the other default activators, it is rooted withDynamicDependency, and the serialization trimmed smoke covers all three default activators.options: nullkeep usingJsonSerializerOptions.Default, behind one accessor with a scoped suppression. Trimmed and NativeAOT publishing disables System.Text.Json reflection. With reflection disabled,JsonSerializerOptions.Defaultuses an empty type-info resolver, so missing metadata surfaces as the existing configuration error.JsonSerializerContext. The stored JSON is unchanged; a new test pins the wire format.AzureTableStorageJournalingProviderBuilderreads each configurable member ofAzureTableJournalStorageOptionsand its nestedClientOptions(EnableTenantDiscovery,Retry,Diagnostics) withConfigurationBinder.GetValue. On net10.0, the project enables the configuration-binding source generator, which binds these values without reflection. LikeBind, invalid values throwInvalidOperationException. The generator can't bind these four types as objects: they expose client instances, pipeline policies and delegates, and the Azure option types lack public constructors. For them it reports SYSLIB1100/SYSLIB1101, which#pragma,[SuppressMessage]and.editorconfigcan't suppress at a call site. When theClientOptionssection is present, the builder createsTableClientOptionsif it isn't already set. net8.0 uses the reflection-based binder for the same calls.DurableJobsEventswrites every payload through one private helper. The helper constrainsTEventto the event base type and annotates it withPublicFields | PublicProperties, which is a superset of whatDiagnosticSource.Write<T>requires. A single justifiedIL2026suppression covers it.DiagnosticSource.Writeis unconditionally[RequiresUnreferencedCode], so keepingDiagnosticListenerrequires this one suppression.GetJournalStorageOptions<TOptions>carries thePublicParameterlessConstructorrequirement through toIOptions<TOptions>/IOptionsMonitor<TOptions>.TreatWarningsAsErrors, any new warning fails the build.Rationale
IsAotCompatible. That property also stamps the assemblies as trimmable, so ILLink would trim them in the default partial mode. Their requiredOrleans.Core/Orleans.Runtimedependencies still carry unresolved trimming and AOT warnings, and the NativeAOT smoke scenarios don't exercise journaling. Enabling the analyzers stops regressions in this code without claiming end-to-end AOT support.Microsoft Reviewers: Open in CodeFlow