Repository navigation
Make predictive C# sessions Native AOT-safe - #1314
Merged
Akshay Sonawane (apsonawane) merged 3 commits intoNov 10, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
November 10, 2026 07:06
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The sample publish overwrites the net8.0 SDK assembly without the required version properties, causing the subsequent pack step to include incorrect version metadata despite the earlier version check.
1 open issue
What changed in this PR
This PR isolates predictive-session JSON serialization from OpenAI types so C# applications can use typed ranking and decision helpers with Native AOT.
Changes:
- Move predictive DTO registrations into a dedicated source-generated context and update both session helpers.
- Replace reflection-based JSON creation in the example and enable Native AOT with selected diagnostics treated as errors.
- Add a CI Native AOT publish check for the example.
| File | Description |
|---|---|
sdk_v2/cs/src/RankingSession.cs |
Use the isolated predictive serialization context. |
sdk_v2/cs/src/Detail/NonGenerativeJsonSerializationContext.cs |
Define source-generated metadata for predictive DTOs. |
sdk_v2/cs/src/Detail/JsonSerializationContext.cs |
Remove predictive registrations from the shared context. |
sdk_v2/cs/src/DecisionSession.cs |
Use the isolated predictive serialization context. |
sdk_v2/cs/examples/RankingAndDecision/RankingAndDecision.csproj |
Enable Native AOT and diagnostic enforcement. |
sdk_v2/cs/examples/RankingAndDecision/Program.cs |
Create JSON values without reflection-based serialization. |
.pipelines/templates/steps-build-cs.yml |
Publish the predictive example with Native AOT in CI. |
Review effort: Balanced
Baiju Meswani (baijumeswani)
approved these changes
Nov 10, 2026
Akshay Sonawane (apsonawane)
deleted the
asonawane/predictive-json-aot
branch
November 10, 2026 09:13
This branch was successfully deployed
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.

Summary
Make the C#
RankingSession.RankAsyncandDecisionSession.DecideAsynchelpers safe to consume from Native AOT applications.Problem
Predictive DTOs were registered in the SDK's shared
JsonSerializationContext, which also contains Betalgo OpenAI types. Referencing the typed predictive helpers rooted that full context and caused Native AOT consumers to fail with BetalgoMessageConverterIL2026/IL3050diagnostics.This blocks direct typed-session use in microsoft/foundry-local-cli#73.
Changes
NonGenerativeJsonSerializationContext.RankingSessionandDecisionSessionat the isolated context.Validation
net8.0,net9.0, andnetstandard2.0.IL2026,IL3050, BetalgoIL2104, orIL3053warnings.