Repository navigation
Fix previous-nuget under native AOT: read NuGet feed JSON with System.Text.Json - #63
Merged
Merged
Conversation
…der AOT NuGet.Protocol deserialises registration pages with Newtonsoft.Json by reflection. In the native-AOT binary, trimming removes the constructors that reflection binds to, so previous-nuget failed with "Unable to find a constructor to use for type NuGet.Packaging.PackageDependencyGroup". Rooting NuGet.Protocol and Newtonsoft.Json did not cover it, because the type lives in NuGet.Packaging. Turn on NuGet's NuGet.UseSystemTextJsonDeserialization feature switch instead, which NuGet documents for AOT consumers: it uses its source-generated System.Text.Json path, and Trim="true" lets the trimmer drop the Newtonsoft.Json path. The two TrimmerRootAssembly items are no longer needed, NuGet's IL2026 trim warnings are gone, and the osx-arm64 binary shrinks from 26 MB to 18 MB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A new smokeaot build target publishes the AOT binary for the current machine and diffs previous-nuget|Proc|0.18.0 against nuget|Proc|0.20.0 with it, failing unless it finds 0.17.0 and suggests a version change. The aot-pack job runs it on every RID, since the framework-dependent build cannot catch what trimming breaks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Make.Fs 0.25 accepts the bare flag as well, so this works before and after the dependency bump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #62
The
previous-nugetprovider crashed in the native-AOT build (0.18.0 onwards) withJsonSerializationException: Unable to find a constructor to use for type NuGet.Packaging.PackageDependencyGroup.Root cause
PreviousNugetLocatorcallsPackageMetadataResource.GetMetadataAsync, and NuGet.Protocol deserialises the registration pages it fetches with Newtonsoft.Json by reflection. In the AOT binary, trimming removes the constructors that reflection binds to. The csproj already rootedNuGet.ProtocolandNewtonsoft.Json(TrimmerRootAssembly), butPackageDependencyGrouplives inNuGet.Packaging, which was still trimmed.Fix
Rather than root another assembly, this turns on the feature switch that NuGet documents for AOT consumers:
With the switch on, NuGet.Protocol reads feed JSON through its source-generated System.Text.Json path, and
Trim="true"lets the trimmer drop the Newtonsoft.Json path. That removes the reflection path instead of keeping it alive:TrimmerRootAssemblyitems are removed;ServiceIndexResourceV3,RepositorySignatureResource, plugins) are gone from the AOT publish. The only IL warnings left come from the vendored JustDecompile assemblies;The switch also applies to the framework-dependent
anybuild, so both builds run the same deserialisation code.Regression check
A new
./build.sh smokeaottarget publishes the native-AOT binary for the current machine and runsdiff 'previous-nuget|Proc|0.18.0' 'nuget|Proc|0.20.0' --target Proc. It fails unless the output shows the previous release (0.17.0) and a suggested version change. CI'saot-packjob runs it after packing, on every RID it builds. AGENTS.md now describes the switch in place of the old rooting note.Not in this PR
#57 is a separate bug in
NuGetAssemblyProvider, not the deserialisation path. Both providers unpack intodiffer/nuget/<id>/<spec version>, andprevious-nugetuses the current version as that folder name. Soprevious-nuget|X|vandnuget|X|vend up side by side in one folder.NuGetPackagethen treats each as a dependency of the other, andCopyAssembliescopies one version's dlls over the other'slib/, which is why the diff comes back empty. I reproduced it here:previous-nuget|Proc|0.20.0againstnuget|Proc|0.20.0reports "No diff" with this fix in place. Keyed by provider name, the folders would no longer collide. It is left for its own PR.Verify (local, macOS arm64, .NET SDK 11.0.100)
origin/main(dotnet publish -f net10.0 -r osx-arm64):previous-nuget|Proc|0.20.0threw the reported exception.previous-nuget|Proc|0.18.0againstnuget|Proc|0.20.0prints the real API changes andSuggested version change: Major../build.sh smokeaot -spasses. To check the check, I restored the old csproj and re-ran it: it failed with the previous-nuget crashes in 0.18: no constructor for PackageDependencyGroup #62 exception, then passed again once the fix was back.mise run ci: build, pack, validate and the API diff (which runsprevious-nugeton the JIT build with the switch on) all pass, andcurb checkreports 0 changes.mise run check(curb, zizmor): no findings.actionlintpassed, run with shellcheck disabled because shellcheck is not installed here.🤖 Generated with Claude Code