Add AssemblyLoadContext.SetAssemblyLocationOverride#129773
Conversation
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
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
There was a problem hiding this comment.
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 internalResolveAssemblyLocationhelper inSystem.Private.CoreLib. - Updates CoreCLR/Mono/NativeAOT
Assembly.Locationimplementations 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>
|
Could you please sign the Contributor License Agreement? This is good to go otherwise. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Just awaiting confirmation from our legal dept. |
|
@dotnet-policy-service agree company="Unity Technologies SF" |
|
@elinor-fung Could you please review and merge? |
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