Preserve HybridCacheEntryOptions.ToDistributedCacheEntryOptions from trimming#130403
Open
svick wants to merge 1 commit into
Open
Preserve HybridCacheEntryOptions.ToDistributedCacheEntryOptions from trimming#130403svick wants to merge 1 commit into
svick wants to merge 1 commit into
Conversation
…trimming In .NET 11, Microsoft.Extensions.Caching.Abstractions was added to the base shared framework (dotnet/dotnet#5206, decision in dotnet#67487), so its assembly is now ILLink-trimmed in the framework. Previously it shipped only as an untrimmed NuGet package. HybridCacheEntryOptions.ToDistributedCacheEntryOptions is internal and has no in-assembly caller; its only consumer is Microsoft.Extensions.Caching.Hybrid, which reaches it via [UnsafeAccessor]. The trimmer cannot follow cross-assembly UnsafeAccessor references, so the method was removed from the shared-framework build, causing a MissingMethodException at runtime. Add an ILLink.Descriptors.xml entry to preserve the method, plus a trimming test that exercises the UnsafeAccessor access pattern and fails if the method is trimmed away. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-caching |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ensures an internal helper on HybridCacheEntryOptions remains present after framework trimming, since it’s accessed cross-assembly via [UnsafeAccessor] and therefore has no static metadata edge for the trimmer to follow.
Changes:
- Add an ILLink descriptor to preserve
HybridCacheEntryOptions.ToDistributedCacheEntryOptions(). - Add a trimming test console app that uses
[UnsafeAccessor]to validate the method survives trimming and behaves as expected. - Add a new trimming test project entry for
Microsoft.Extensions.Caching.Abstractions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.Caching.Abstractions/tests/TrimmingTests/Microsoft.Extensions.Caching.Abstractions.TrimmingTests.proj | Registers the new trimming console-app test source file for the trimming test harness. |
| src/libraries/Microsoft.Extensions.Caching.Abstractions/tests/TrimmingTests/HybridCacheEntryOptionsAccessorTest.cs | Exercises [UnsafeAccessor] access to ToDistributedCacheEntryOptions and validates expected option propagation. |
| src/libraries/Microsoft.Extensions.Caching.Abstractions/src/ILLink/ILLink.Descriptors.xml | Preserves the internal HybridCacheEntryOptions.ToDistributedCacheEntryOptions method during trimming. |
svick
added a commit
to svick/runtime
that referenced
this pull request
Jul 9, 2026
The LibraryBuild descriptor is only applied during the library's own build-time trim pass and is not embedded into the shipping assembly, so it does not protect ToDistributedCacheEntryOptions against downstream app trimming (the shared-framework scenario in dotnet#130376). That is fixed separately and correctly via an embedded ILLink.Descriptors.xml in dotnet#130403, so this file is removed to avoid redundancy and a merge collision. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 9, 2026
Open
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 #130376
Summary
In .NET 11,
Microsoft.Extensions.Caching.Abstractionswas added to the base shared framework (dotnet/dotnet#5206, decision in #67487). As a result, its assembly is now ILLink-trimmed as part of the framework, whereas previously it shipped only as an untrimmed NuGet package.HybridCacheEntryOptions.ToDistributedCacheEntryOptions()isinternaland has no caller inside its own assembly. Its only consumer is theMicrosoft.Extensions.Caching.Hybridimplementation package, which reaches it via[UnsafeAccessor]. The trimmer cannot follow cross-assemblyUnsafeAccessorreferences (they resolve by name at runtime, with no metadata edge), so the method was trimmed out of the shared-framework build. This surfaces as aMissingMethodExceptionat runtime for the Hybrid cache.Fix
ILLink.Descriptors.xmlto preserve the method (auto-embedded viaeng/illink.targets).UnsafeAccessoraccess pattern and returns100only when the method resolves.Validation
Verified with a full self-contained
TrimMode=fullpublish:100; the method is present in the trimmed assembly.[Failed Test]with exit code-532462766(0xE0434352, theMissingMethodException), confirming the test guards the fix.Note
This pull request was authored by Copilot (AI).