Skip to content

Remove suppression and Fix trim warnings#7488

Merged
Nigusu-Allehu merged 4 commits into
devfrom
dev-nyenework-update-nsj-version
Jun 19, 2026
Merged

Remove suppression and Fix trim warnings#7488
Nigusu-Allehu merged 4 commits into
devfrom
dev-nyenework-update-nsj-version

Conversation

@Nigusu-Allehu

@Nigusu-Allehu Nigusu-Allehu commented Jun 17, 2026

Copy link
Copy Markdown
Member

Bug

Fixes: #7453 (comment)

Description

The Newtonsoft.Json version upgrade exposed IL2026/IL3050 trimming/AOT warnings because the newer version annotates JsonConvert.DeserializeObject<T>() with [RequiresUnreferencedCode]/[RequiresDynamicCode]. Rather than cascading these attributes up the entire credential service call chain, this PR replaces the NSJ call in PluginCredentialProvider with System.Text.Json source-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 here PluginCredentialResponse is 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

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PluginCredentialProvider with System.Text.Json.JsonSerializer.Deserialize(..., JsonTypeInfo) to avoid reflection-based trim warnings.
  • Add a source-generated JsonSerializerContext and 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.

Comment thread Directory.Packages.props
@Nigusu-Allehu Nigusu-Allehu marked this pull request as ready for review June 17, 2026 20:19
@Nigusu-Allehu Nigusu-Allehu requested a review from a team as a code owner June 17, 2026 20:19
@Nigusu-Allehu Nigusu-Allehu self-assigned this Jun 17, 2026
@Nigusu-Allehu Nigusu-Allehu force-pushed the dev-nyenework-update-nsj-version branch from ec150a7 to 5f0480b Compare June 18, 2026 18:01
@Nigusu-Allehu Nigusu-Allehu changed the title Update NSJ version and Fix trim warnings Remove suppression and Fix trim warnings Jun 18, 2026
@Nigusu-Allehu Nigusu-Allehu merged commit 55d960a into dev Jun 19, 2026
20 of 21 checks passed
@Nigusu-Allehu Nigusu-Allehu deleted the dev-nyenework-update-nsj-version branch June 19, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants