Remove suppression and Fix trim warnings#7488
Merged
Merged
Conversation
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Newtonsoft.Json dependency and switches PluginCredentialProvider’s response deserialization from Newtonsoft.Json to System.Text.Json using source generation (to address trimming warnings), with new tests validating behavioral parity between the two serializers.
Changes:
- Bump Newtonsoft.Json from 13.0.3 to 13.0.4 via central package management.
- Replace plugin response deserialization in
PluginCredentialProviderwithSystem.Text.Json.JsonSerializer.Deserialize(..., JsonTypeInfo)to avoid reflection-based trim warnings. - Add a source-generated
JsonSerializerContextand new tests comparing Newtonsoft.Json vs System.Text.Json deserialization outcomes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/NuGet.Core.Tests/NuGet.Credentials.Test/PluginCredentialResponseDeserializationTests.cs | Adds parity tests for STJ vs NSJ deserialization behavior. |
| src/NuGet.Core/NuGet.Credentials/PluginCredentialResponseJsonContext.cs | Introduces STJ source-generated context for PluginCredentialResponse. |
| src/NuGet.Core/NuGet.Credentials/PluginCredentialProvider.cs | Switches plugin stdout JSON deserialization from NSJ to STJ source-gen to mitigate trim warnings. |
| Directory.Packages.props | Updates Newtonsoft.Json package version centrally. |
ec150a7 to
5f0480b
Compare
kartheekp-ms
approved these changes
Jun 19, 2026
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.
Bug
Fixes: #7453 (comment)
Description
The
Newtonsoft.Jsonversion upgrade exposedIL2026/IL3050trimming/AOT warnings because the newer version annotatesJsonConvert.DeserializeObject<T>()with[RequiresUnreferencedCode]/[RequiresDynamicCode]. Rather than cascading these attributes up the entire credential service call chain, this PR replaces the NSJ call inPluginCredentialProviderwithSystem.Text.Jsonsource-generated deserialization, eliminating the warnings at the source.Unlike the dual NSJ/STJ code paths behind a feature switch in
NuGet.Protocol, I don't see a reason to be that careful herePluginCredentialResponseis a trivial 4-property POCO with no custom converters or polymorphism, and I've added parity tests that deserialize the same inputs with both NSJ and STJ and assert equal results.PR Checklist