Skip to content

Add AssemblyLoadContext.SetAssemblyLocationOverride#129773

Open
cdmazom wants to merge 6 commits into
dotnet:mainfrom
cdmazom:issue-127097
Open

Add AssemblyLoadContext.SetAssemblyLocationOverride#129773
cdmazom wants to merge 6 commits into
dotnet:mainfrom
cdmazom:issue-127097

Conversation

@cdmazom

@cdmazom cdmazom commented Jun 23, 2026

Copy link
Copy Markdown

Adds a static, set-once callback that overrides the value returned by Assembly.Location. The callback is stored in the shared AssemblyLoadContext and applied by RuntimeAssembly.Location on CoreCLR, Mono, and NativeAOT.

Updates the System.Runtime.Loader reference assembly and adds tests covering the override, the set-once guard, and null handling.

Fix #127097

Adds a static, set-once callback that overrides the value returned by
Assembly.Location. The callback is stored in the shared
AssemblyLoadContext and applied by RuntimeAssembly.Location on CoreCLR,
Mono, and NativeAOT.

Updates the System.Runtime.Loader reference assembly and adds tests
covering the override, the set-once guard, and null handling.

Fix dotnet#127097
Copilot AI review requested due to automatic review settings June 23, 2026 21:58
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 23, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
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

This PR introduces a new public API, AssemblyLoadContext.SetAssemblyLocationOverride, which allows a process-wide, set-once callback to override the value returned by Assembly.Location. The override is applied consistently across CoreCLR, Mono, and NativeAOT by routing each runtime’s RuntimeAssembly.Location implementation through a shared resolver in AssemblyLoadContext.

Changes:

  • Adds AssemblyLoadContext.SetAssemblyLocationOverride(Func<Assembly, string, string>) and an internal ResolveAssemblyLocation helper in System.Private.CoreLib.
  • Updates CoreCLR/Mono/NativeAOT Assembly.Location implementations to apply the override.
  • Updates the System.Runtime.Loader reference assembly and adds tests for null argument, override behavior, and set-once enforcement.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs Adds the set-once callback storage, public setter API, and internal location resolver used by all runtimes.
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs Applies the location override when returning Assembly.Location on CoreCLR.
src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs Applies the location override when returning Assembly.Location on Mono.
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs Applies the location override when returning Assembly.Location on NativeAOT.
src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs Adds the new public API to the reference assembly surface.
src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs Adds tests for null argument, stream-loaded override behavior, and set-once guard (RemoteExecutor isolation).
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Adds SR string for the “already set” exception message.

Co-authored-by: Theodore Tsirpanis <teo@tsirpanis.gr>
Copilot AI review requested due to automatic review settings June 24, 2026 19:45

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 7 out of 7 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings June 25, 2026 01:55

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 7 out of 7 changed files in this pull request and generated 1 comment.

@jkotas jkotas left a comment

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.

Thanks!

@jkotas

jkotas commented Jun 25, 2026

Copy link
Copy Markdown
Member

Could you please sign the Contributor License Agreement? This is good to go otherwise.

Comment thread src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Outdated
Copilot AI review requested due to automatic review settings June 25, 2026 23:03

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 7 out of 7 changed files in this pull request and generated 1 comment.

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 25, 2026 23:15

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 7 out of 7 changed files in this pull request and generated 1 comment.

@cdmazom

cdmazom commented Jun 26, 2026

Copy link
Copy Markdown
Author

Could you please sign the Contributor License Agreement? This is good to go otherwise.

Just awaiting confirmation from our legal dept.

@cdmazom

cdmazom commented Jul 3, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Unity Technologies SF"

@jkotas jkotas requested a review from elinor-fung July 3, 2026 17:24
@jkotas

jkotas commented Jul 3, 2026

Copy link
Copy Markdown
Member

@elinor-fung Could you please review and merge?

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

Labels

area-System.Reflection community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Support non-locking assembly loading with preserved Assembly.Location

4 participants