Use System.Text.Json source generation to remove some trim/AOT warnings - #4683
charlesroddie wants to merge 1 commit into
Conversation
Replaces reflection-based JsonSerializer calls in SqlVector, SqlParameter and HostGuardianServiceEnclaveProvider with a JsonSerializerContext, removing IL2026/IL3050 warnings. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
This PR removes trim/NativeAOT warnings by switching JSON (de)serialization from reflection-based JsonSerializer APIs to System.Text.Json source-generated metadata via a new internal SqlClientJsonSerializerContext.
Changes:
- Added
SqlClientJsonSerializerContextwith[JsonSerializable]entries for the JSON types used. - Updated
SqlVector<T>.GetString()to serialize using source-generatedJsonTypeInfo. - Updated
SqlParametervector coercion andVirtualSecureModeEnclaveProvider.MakeRequestto deserialize using source-generatedJsonTypeInfo.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs | Uses source-generated type info for vector JSON serialization |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/VirtualSecureModeEnclaveProvider.cs | Uses source-generated type info for HGS response deserialization |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs | Uses source-generated type info for string-to-vector JSON coercion |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientJsonSerializerContext.cs | Introduces the source-generation context and registered serializable types |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4683 +/- ##
==========================================
- Coverage 66.27% 64.60% -1.67%
==========================================
Files 290 284 -6
Lines 45062 68015 +22953
==========================================
+ Hits 29865 43943 +14078
- Misses 15197 24072 +8875
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Replaces reflection-based
JsonSerializercalls with an internalJsonSerializerContext(SqlClientJsonSerializerContext), removing the IL2026/IL3050 warnings they raise under trimming and Native AOT:SqlVector<T>.GetString()– serializesReadOnlyMemory<float>(the constructor already restrictsTtofloat).SqlParameterstring-to-vector coercion – deserializesfloat[].HostGuardianServiceEnclaveProvider.MakeRequest– deserializesList<byte>.Trim/AOT warnings with
-p:IsAotCompatible=true(unique by location and code):No public API or behavioral changes; JSON output is unchanged.
Issues
Part of #1947.
Testing
-p:IsAotCompatible=true; none of the touched files emit trim/AOT warnings.SqlVector/SqlParameterunit tests (including exactGetString()output) pass on net462, net8.0 and net10.0.🤖 Generated with Claude Code