Repository navigation
NuGet.Protocol should not use Newtonsoft.Json when AoT trimmed - #7493
Merged
Merged
Conversation
nkolev92
reviewed
Jun 19, 2026
nkolev92
left a comment
Member
There was a problem hiding this comment.
There's some compile errors, so that needs fixed.
100% of my feedback is var usage for readability. It would've made it easier to read for me.
The tests part, I was surprised to see none.
HttpStreamValidationTests could use some coverage.
DependencyInfoResourceV3 doesn't seem to have direct tests either, which is the ResolverMetadataClient.
DownloadResourceV3 similarly doesn't seem exercised mcuh, if at all.
Finally, RegistrationResourceV3 is missing some direct coverage, but maybe covered through other.
zivkan
force-pushed
the
dev-zivkan-protocol-aot-no-newtonsoft-json
branch
from
June 21, 2026 10:37
a348049 to
0a1d0e3
Compare
jebriede
reviewed
Jun 23, 2026
jebriede
previously approved these changes
Jun 23, 2026
jebriede
left a comment
Contributor
There was a problem hiding this comment.
Approving with one suggestion.
nkolev92
approved these changes
Jun 23, 2026
nkolev92
left a comment
Member
There was a problem hiding this comment.
Thanks for adding those additional tests.
Much more robust now.
jebriede
approved these changes
Jun 23, 2026
Nigusu-Allehu
approved these changes
Jun 23, 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: follow up on other NuGet.Protocol AoT work
Description
When running
dotnet publishon an AoT app, you can use/p:IlcGenerateMapFile=true /p:IlcGenerateDgmlFile=trueto generate extra diagnostic output which can be used to analyze what's contributing to the size of the executable, and the dependency graph of all the methods. This was used to determine that several megabytes of Newtonsoft.Json code was being included, and what parts of NuGet.Protocol were calling it (bringing it in).Fixing the code reduces the AoT trimmed app by about 6 MB. There's no longer any Newtonsoft.Json code in the symbol map, but there is about 4.5 KB of metadata because some of NuGet.Protocol's public APIs return types like JObject, even if those APIs are never called.
There are basically two groups of changes:
ToString()implementations. These were switched over to System.Text.Json equivalents, even when the feature flag is not enabled. It's low risk because it's not parsing json provided by 3rd parties.JObject. Therefore, it's not possible to create Stj and Nj methods and have the existing public API call it. Instead, a new method with a strongly typed return type needs to be created, leading to what looks like a lot of duplicated code.PR Checklist
Added testsN/A, more of a refactoring. Existing tests that test the feature flag should already follow the new code paths.Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.N/A