Repository navigation
Annotate TValue on ConditionalWeakTable.Remove polyfill to fix IL2091 - #616
Merged
Merged
Conversation
ConditionalWeakTable<TKey, TValue> declares TValue with DynamicallyAccessedMembers(PublicParameterlessConstructor). The Remove(key, out value) polyfill did not, so trim analysis reported IL2091 for any consumer that roots its assembly. Root the ConsumeTrimmed assembly so the trimmer analyzes every polyfill, not only the reachable ones. Fixes #615
This was referenced Oct 5, 2026
This was referenced Oct 9, 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.
Fixes #615
ConditionalWeakTable<TKey, TValue>declaresTValuewith[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)](net6.0 through net10.0). TheRemove(key, out value)polyfill declaredTValuewithout it, so trim analysis reported IL2091 for any consumer that roots its assembly, even if it never callsRemove.Changes
Polyfill_ConditionalWeakTable.cs: annotateTValueto matchConditionalWeakTable. Split copies regenerated.ConsumeTrimmed.csproj: add<TrimmerRootAssembly Include="$(AssemblyName)" />. The project previously only trimmed reachable code, and nothing reachable callsRemove, so the trimmer never analyzed it. Rooting the assembly makes it analyze every polyfill.assemblySize.include.md: regenerated byApiBuilderTests.Verification
ConsumeTrimmedfailed with the IL2091 from the issue, and it was the only trim warning.PublishAll) is clean on net7.0 through net11.0.Consumecompiles on all target frameworks.ConditionalWeakTableRemovepasses on net48 and net9.0.Note
CI builds
ConsumeTrimmedbut does not publish it, so the rooting only catches this class of bug whenPublishAllis run. A publish step inbuild.ymlwould make it a standing guard; not included here.