Repository navigation
Fix NativeAOT reflection ref-return storage lifetime - #135172
Merged
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix MethodInfo.Invoke returning wrong object for ref-returning methods
Fix NativeAOT reflection ref-return storage lifetime
Oct 3, 2026
jkotas
reviewed
Oct 3, 2026
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
Member
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The regression test does not reliably reproduce the compacting-GC timing required to expose the original lifetime bug.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes NativeAOT reflection ref-return lifetime handling by transforming returned references before temporary argument storage expires.
Changes:
- Moves return transformation into all argument helper paths.
- Adds ref-return identity and null-result tests across invocation APIs.
| File | Description |
|---|---|
DynamicInvokeInfo.cs |
Transforms results within temporary-storage lifetimes. |
MethodInvokerTests.cs |
Adds ref-return regression scenarios. |
This was referenced Oct 4, 2026
Open
EgorBo
approved these changes
Oct 4, 2026
Member
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.

NativeAOT reflection invocation can return a byref into a helper’s temporary argument storage. Dereferencing it after the helper returns can yield a stale or incorrect object.
object?, transforming results before their argument storage expires or GC registrations are removed. Copy-back and exception wrapping remain unchanged.MethodInfo.InvokeandMethodInvokerspan/fixed-argument paths, checking object identity and null results.