Skip to content

Ensure NuGet.Protocol is AOT/trim-warning-free with proper annotations and feature switch isolation - #7472

Merged
Nigusu-Allehu merged 4 commits into
devfrom
dev-nyenework-annotate-and-fix
Jun 12, 2026
Merged

Nigusu-Allehu merged 4 commits into
devfrom
dev-nyenework-annotate-and-fix

Conversation

@Nigusu-Allehu

@Nigusu-Allehu Nigusu-Allehu commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

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 a PublishAot application.

  • Added [RequiresUnreferencedCode]/[RequiresDynamicCode] on MessageUtilities.SerializePayload, MessageUtilities.DeserializePayload<T>, and the RepositorySignatureResource(JObject, SourceRepository) constructor
  • Added [UnconditionalSuppressMessage] on internal plugin request handlers where DeserializePayload is called but the reflection path is unreachable (payload is always a pre-deserialized typed object from STJ's MessageConverter)
  • Restructured feature-switch-guarded code in Sender, StandardInputReceiver, StandardOutputReceiver, and RepositorySignatureResourceProvider to use if/else if pattern 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 have FeatureSwitch || getenvVariable(). However, even if FeatureSwitch is 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

@Nigusu-Allehu Nigusu-Allehu changed the title Dev nyenework annotate and fix Ensure NuGet.Protocol is AOT/trim-warning-free with proper annotations and feature switch isolation Jun 11, 2026
@Nigusu-Allehu
Nigusu-Allehu marked this pull request as ready for review June 11, 2026 21:40
@Nigusu-Allehu
Nigusu-Allehu requested a review from a team as a code owner June 11, 2026 21:40
@Nigusu-Allehu Nigusu-Allehu self-assigned this Jun 11, 2026
@Nigusu-Allehu
Nigusu-Allehu marked this pull request as draft June 11, 2026 21:48
@Nigusu-Allehu
Nigusu-Allehu marked this pull request as ready for review June 11, 2026 23:35
}
else
{
using var reader = new StreamReader(await stream.AsSeekableStreamAsync(token));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@Nigusu-Allehu
Nigusu-Allehu merged commit 551e8ba into dev Jun 12, 2026
20 of 21 checks passed
@Nigusu-Allehu
Nigusu-Allehu deleted the dev-nyenework-annotate-and-fix branch June 12, 2026 21:46
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.

Remove feature switch || runtime check() used in nuget.client repo

3 participants