Skip to content

Implement Assembly.GetCallingAssembly for native AOT#129963

Open
MichalStrehovsky wants to merge 4 commits into
dotnet:mainfrom
MichalStrehovsky:port-getcallingasm
Open

Implement Assembly.GetCallingAssembly for native AOT#129963
MichalStrehovsky wants to merge 4 commits into
dotnet:mainfrom
MichalStrehovsky:port-getcallingasm

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Fixes #129961

  • Use stack trace data to find the calling assembly.
  • It is therefore only supportable if stack trace data is available. Block for the same reason under F5 debugging (CoreCLR). This is why it's a breaking change.
  • Maintain an arbitrary list of methods to skip in stacktraces to make calling this API work in a .cctor. Matches similar arbitrary list in CoreCLR to the extent that is covered by tests.
  • canTailCall is now same between ILC and crossgen2.

Fixes dotnet#129961

* Use stack trace data to find the calling assembly.
* It is therefore only supportable if stack trace data is available. Block for the same reason under F5 debugging (CoreCLR). This is why it's a breaking change.
* Maintain an arbitrary list of methods to skip in stacktraces to make calling this API work in a .cctor. Matches similar arbitrary list in CoreCLR to the extent that is covered by tests.
* `canTailCall` is now same between ILC and crossgen2.
Copilot AI review requested due to automatic review settings June 29, 2026 03:28
@MichalStrehovsky MichalStrehovsky added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Jun 29, 2026
@dotnet-policy-service dotnet-policy-service Bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jun 29, 2026
@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.

Pull request overview

Enables Assembly.GetCallingAssembly() on NativeAOT by deriving the calling assembly from stack-trace metadata, and updates the toolchain/JIT interface to keep tailcall behavior consistent across ILC and crossgen2. The PR also re-enables/extends relevant reflection tests now that NativeAOT support is present.

Changes:

  • Implement Assembly.GetCallingAssembly() for NativeAOT using StackFrame + DiagnosticMethodInfo when stack traces are supported.
  • Gate GetCallingAssembly() on StackTrace.IsSupported (CoreCLR + NativeAOT) with a new resource string for the error.
  • Unify canTailCall handling by moving logic into the common JIT interface implementation and adjust tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs Adds NativeAOT implementation of GetCallingAssembly() via stack walking and method info extraction.
src/coreclr/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs Adds a StackTrace.IsSupported gate before CoreCLR’s existing stack-crawl-based implementation.
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Adds a new resource string for the “stack trace support disabled” error path.
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Centralizes canTailCall logic and adjusts method attribute reporting for RequireSecObject.
src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs Removes duplicate canTailCall implementation in favor of the common version.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs Removes duplicate canTailCall implementation in favor of the common version.
src/libraries/System.Runtime/tests/System.Reflection.Tests/AssemblyTests.cs Re-enables NativeAOT coverage and adds a delegate-based GetCallingAssembly test.
src/libraries/System.Runtime/tests/System.Reflection.Tests/MethodInfoTests.cs Re-enables the aggressive-inlining callstack test on NativeAOT by removing an ActiveIssue skip.
src/libraries/System.Runtime/tests/System.Reflection.Tests/TestAssembly/ClassToInvoke.cs Adds a helper method to invoke a delegate from a separate assembly for test coverage.

Comment thread src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 03:47
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 03:57
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

continue;

// Skip the static constructor invocation machinery so that a GetCallingAssembly
// called from a class constructor sees the assembly that triggered the cctor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CoreCLR skips reflection invoke too. Do we care?

bool SystemDomain::IsReflectionInvocationMethod(MethodDesc* pMeth)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, that's the "Matches similar arbitrary list in CoreCLR to the extent that is covered by tests." part of the PR description. If we don't care enough to have tests, then we probably don't care.

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr breaking-change Issue or PR that represents a breaking API or functional change over a previous release. needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ci-scan] Test failure: ShutdownTests.ShutdownTestRun on NativeAOT (Assembly.GetCallingAssembly not supported)

3 participants