Mark projects as AOT compatible - #3998
Conversation
| <!-- The configuration binding source generator emits these diagnostics for the certificate | ||
| object graph on MicrosoftIdentityApplicationOptions (X509Certificate2, PublicKey, PrivateKey, | ||
| etc.), which is never populated from configuration. Suppressed to match the AOT test app. --> | ||
| <NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101;SYSLIB0026;SYSLIB0027;SYSLIB0028</NoWarn> |
There was a problem hiding this comment.
I don't think this will solve the customer's issue. Ultimtately those properties are not AOT compatible and removing them from config is a breaking change.
There was a problem hiding this comment.
Agreed this moves the compile time issue into a runtime issue
There was a problem hiding this comment.
Bogdan Gavril (@bgavrilMS) You say removing them from the config is a breaking change, but you also approved the PR.
So, does that mean it's worth making it runtime issue instead of a compile time issue (as MARCIN Z (@MZOLN) described it)? Or would it be better to solve the runtime issues as well before merging?
Shifting it to a runtime issue might help the specific customer who asked about it (since it was just being pulled in transitively for them), but could cause more confusing problems if the incompatible stuff ends up getting referenced at runtime.
There was a problem hiding this comment.
How would shifting this to runtime issue help?
There was a problem hiding this comment.
Pull request overview
This PR addresses trimming/Native AOT publish failures caused by reflection-based configuration binding in Microsoft.Identity.Web.OidcFIC by enabling the configuration-binding source generator and marking relevant libraries as AOT compatible, aligning OidcFIC (and related leaf packages) with established patterns already used in other Microsoft Identity Web packages.
Changes:
- Enable
EnableConfigurationBindingGeneratorand setIsAotCompatible(net8.0+) forMicrosoft.Identity.Web.OidcFIC, with targetedSYSLIB*suppressions matching the existing AOT test app pattern. - Mark
Microsoft.Identity.Web.AgentIdentitiesandMicrosoft.Identity.Web.CertificatelessasIsAotCompatible(net8.0+). - Extend the AOT compatibility test app to root
Microsoft.Identity.Web.OidcFICandMicrosoft.Identity.Web.AgentIdentitiesassemblies so the trim/AOT analysis includes these paths.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Microsoft.Identity.Web.AotCompatibility.TestApp.csproj | Roots OidcFIC and AgentIdentities so AOT publish/trim analysis exercises the FIC/agentic path. |
| src/Microsoft.Identity.Web.OidcFIC/Microsoft.Identity.Web.OidcFIC.csproj | Enables config-binding source generator + marks AOT compatibility (net8+), and suppresses known SYSLIB generator diagnostics consistent with the test app. |
| src/Microsoft.Identity.Web.Certificateless/Microsoft.Identity.Web.Certificateless.csproj | Marks the package as AOT compatible for net8.0+ TFMs. |
| src/Microsoft.Identity.Web.AgentIdentities/Microsoft.Identity.Web.AgentIdentities.csproj | Marks the package as AOT compatible for net8.0+ TFMs. |
Referencing the
Microsoft.Identity.Web.OidcFICpackage (the FIC signed-assertion loader used for agentic / cross-cloud Federated Identity Credential scenarios) breaks a trimmed or Native AOT publish of the consuming application. The failure surfaces as anIL2026trim warning that is promoted to a build error, e.g.:Root cause
OidcIdpSignedAssertionLoader.LoadIfNeededAsyncbinds a configuration section toMicrosoftIdentityApplicationOptionsusing the reflection-based configuration binder:ConfigurationBinder.Bind(IConfiguration, object)is annotated[RequiresUnreferencedCode]/[RequiresDynamicCode]. When an application is published with trimming (PublishTrimmed) or Native AOT (PublishAot), ILLink/ILC analyze thewhole call graph, walk into
OidcFIC, and reportIL2026(andIL3050under AOT) for this unguarded reflection call.Unlike the rest of Microsoft Identity Web, the
OidcFICproject set no trim/AOT properties:IsAotCompatible), so the issue was never caught in this repo's own build.EnableConfigurationBindingGenerator), so the reflection-based binder remained in the shipped IL.OidcFICassembly, so the gap was not covered by AOT validation.Changes
All changes are build/packaging configuration and follow the exact pattern already used by
Microsoft.Identity.Web.DownstreamApi,Microsoft.Identity.Web.MicrosoftGraph, and the AOT compatibility test app.1.
src/Microsoft.Identity.Web.OidcFIC/Microsoft.Identity.Web.OidcFIC.csproj2. Regression hardening for sibling packages
In addition to
OidcFICassembly which threw the original issue, two leaf libraries were verified to be trim/AOT-clean but were not yet marked as being compatible. They are now markedIsAotCompatible(net8.0+) to avoid them causing the same errors:src/Microsoft.Identity.Web.AgentIdentities/Microsoft.Identity.Web.AgentIdentities.csproj(the agentic-identity package, which referencesOidcFIC).src/Microsoft.Identity.Web.Certificateless/Microsoft.Identity.Web.Certificateless.csproj.3.
tests/Microsoft.Identity.Web.AotCompatibility.TestAppAn existing test app intended to cover AOT compatibility, but did not reference either
OidcFICorAgentIdentities. This PR adds them to theTrimmerRootAssemblylist so the FIC / agentic path is actually exercised by an AOT publish and this class of regression is caught going forward:Verification
IL2026/IL3050atOidcIdpSignedAssertionLoader.csby buildingOidcFICwith the AOT analyzers enabled.OidcFIC(net8.0/net9.0/net10.0 + net462/net472/netstandard2.0) with the repo defaultTreatWarningsAsErrors=true: 0 warnings, 0 errors.OidcFICassembly (net8.0): 0IL2026/IL3050/NETSDK1144.OidcFICrooted: the entire managed IL scan / trim-and-AOT analysis phase completed with 0 warnings (only the final native link step fails in the local environment because the C++ linker is not on PATH — an environment limitation, not a code issue).OidcIdpSignedAssertionLoadertests pass — binding behavior is preserved.net8/9 gap follow-up
This PR is the limited fix for a customer-reported issue: it makes the
OidcFICpackage (and the verified sibling leaf libraries) trim-/AOT-clean on net8.0, net9.0, and net10.0.It does not attempt to deliver end-to-end trim/AOT support for a full Microsoft Identity Web web app / web API on net8/9. Investigation showed that the AOT-safe web-API entry point —
AddMicrosoftIdentityWebApiAotand its supportingMicrosoftIdentityJwtBearerOptionsPostConfigurator— is gated behind#if NET10_0_OR_GREATER. On net8/9 the only configuration path is the reflection-basedAddMicrosoftIdentityWebApi(IConfiguration, ...), which is inherently not AOT-safe. This is the deliberate reason the AOT compatibility test app andTokenAcquisition'sIsAotCompatiblemarker are net10-focused.The individual leaf libraries (
TokenAcquisition,OidcFIC,AgentIdentities,Certificateless) were confirmed to be trim/AOT-clean on net8/9 in isolation. Closing the full net8/9 gap would require back-porting the reflection-free web-API configuration surface (AddMicrosoftIdentityWebApiAotet al.) to net8/9 — a separate, larger effort tracked independently.