Skip to content

Reject NativeAOT closed static delegates over non-reference first parameters - #136125

Merged
jkotas merged 2 commits into
mainfrom
copilot/resolve-static-delegate-binding-issue
Oct 20, 2026
Merged

jkotas merged 2 commits into
mainfrom
copilot/resolve-static-delegate-binding-issue

Conversation

Copilot AI commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

NativeAOT accepts closed static delegates over non-reference first parameters, passing an object reference where the method expects a value. CoreCLR rejects these bindings.

  • Binding: Reject value-type, byref, pointer, and function-pointer first parameters, including null targets. Throwing overloads report ArgumentException; throwOnBindFailure: false returns null.
  • Coverage: Add cases across affected overloads, generic instantiations, and unsupported signatures; preserve valid reference-type, interface, and array bindings. Scope rejection assertions to CoreCLR and NativeAOT because Mono currently permits some bindings.

@azure-pipelines

azure-pipelines Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix delegate binding issue for closed static delegates Reject NativeAOT closed static delegates over non-reference first parameters Oct 20, 2026
Copilot AI requested a review from jkotas October 20, 2026 04:10
@jkotas
jkotas requested a balanced review from Copilot October 20, 2026 05:05
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human confirmation of CoreCLR and NativeAOT test results is needed; builds and tests were not run during this review.

No open issues 🎉

What changed in this PR

Aligns NativeAOT closed static delegate binding with CoreCLR by rejecting first parameters that cannot receive an object reference.

Changes:

  • Rejects value-type, byref, pointer, and function-pointer first parameters, including null targets.
  • Adds rejection coverage across overloads and generic instantiations, plus tests preserving valid reference bindings.
File Description
src/​libraries/​System.Runtime/​tests/​System.Runtime.Tests/​System/​DelegateTests.cs Tests rejected signatures and valid reference bindings.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeMethodInfo.cs Adds the non-reference first-parameter guard.

Review effort: Balanced

@jkotas
jkotas marked this pull request as ready for review October 20, 2026 05:44
@jkotas

jkotas commented Oct 20, 2026

Copy link
Copy Markdown
Member

@MichalStrehovsky PTLA

@jkotas
jkotas enabled auto-merge (squash) October 20, 2026 06:35
@jkotas
jkotas merged commit 8ab789d into main Oct 20, 2026
136 of 138 checks passed
@jkotas
jkotas deleted the copilot/resolve-static-delegate-binding-issue branch October 20, 2026 08:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NativeAOT binds closed static delegates over value-type first parameters

4 participants