Repository navigation
Ensure NuGet.Protocol is AOT/trim-warning-free with proper annotations and feature switch isolation - #7472
Merged
Conversation
Nigusu-Allehu
marked this pull request as ready for review
June 11, 2026 21:40
Nigusu-Allehu
marked this pull request as draft
June 11, 2026 21:48
Nigusu-Allehu
marked this pull request as ready for review
June 11, 2026 23:35
jebriede
approved these changes
Jun 12, 2026
zivkan
approved these changes
Jun 12, 2026
| } | ||
| else | ||
| { | ||
| using var reader = new StreamReader(await stream.AsSeekableStreamAsync(token)); |
Member
There was a problem hiding this comment.
If you create methods GetNjResultsAsync and GetStjResultsAsync, then this method can be simplified to:
if (NuGetFeatureFlags.UseSystemTextJsonDeserializationFeatureSwitch)
{
return await GetStjResultsAsync(...);
}
else
{
if (NuGetFeatureFlags.IsSystemTextJsonDeserializationEnabledByEnvironment(_environmentVariableReader))
{
return await GetNjResultsAsync(....);
}
else
{
return await GetStjResultsAsync(....);
}
}which I think is easier to read/understand, and reduces the STJ code duplication.
Member
Author
There was a problem hiding this comment.
I like the idea. I will do that in a follow up. The SDK team is now using packages directly from our repo to test their new dotnet-aot app commands. So, I will merge this so that they have access to this commit asap.
This was referenced Jun 13, 2026
5 tasks
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: NuGet/Home#14944
Description
Annotate
NuGet.Protocol's AOT-incompatible code paths with proper trim/AOT attributes to ensure zero ILC warnings when consuming the library from aPublishAotapplication.[RequiresUnreferencedCode]/[RequiresDynamicCode]onMessageUtilities.SerializePayload,MessageUtilities.DeserializePayload<T>, and theRepositorySignatureResource(JObject, SourceRepository)constructor[UnconditionalSuppressMessage]on internal plugin request handlers whereDeserializePayloadis called but the reflection path is unreachable (payload is always a pre-deserialized typed object from STJ'sMessageConverter)Sender,StandardInputReceiver,StandardOutputReceiver, andRepositorySignatureResourceProviderto useif/else ifpattern instead of||. In the issue attached I have another link reporting an issue in the runtime repo. The repro I attached there, shows that the trimmer warns when the condition statement that contains a feature switch contains a runtime condition even if it is guaranteed the logic evaluates to always one vlaue. In our case we haveFeatureSwitch || getenvVariable(). However, even ifFeatureSwitchis true. we still get a warning from the else block of code which should have been trimmed out. I was able to fix this by making the FeatureSwitch the singular condition.PR Checklist
I tested this by adding NuGet.protocl as a dependency in a native app that would call all its public APIs and publishing it https://github.com/Nigusu-Allehu/NuGetAotTest