Skip to content

Add SYSTEM_CORELIB_DIRECTORY host property for explicit CoreLib location#128734

Merged
elinor-fung merged 4 commits into
dotnet:mainfrom
elinor-fung:system-corelib-dir-prop
Jun 3, 2026
Merged

Add SYSTEM_CORELIB_DIRECTORY host property for explicit CoreLib location#128734
elinor-fung merged 4 commits into
dotnet:mainfrom
elinor-fung:system-corelib-dir-prop

Conversation

@elinor-fung
Copy link
Copy Markdown
Member

@elinor-fung elinor-fung commented May 28, 2026

Add a new well-known host runtime property, SYSTEM_CORELIB_DIRECTORY, that lets a host explicitly specify the directory containing System.Private.CoreLib.dll. When set, the runtime loads CoreLib from that directory instead of the default lookup beside coreclr, and the single-file bundle-extraction fallback is also skipped.

#128278 removed the TPA-scanning fallback in BindToSystem, which broke scenarios (notably mobile platforms like iOS) where coreclr is not next to System.Private.CoreLib.dll is not located beside it (see comment on #128278). Rather than restoring implicit scanning, this PR provides an explicit, opt-in contract for hosts to point the runtime at CoreLib.

  • Property is treated as an authoritative override. When set, no fallback search is performed - if the file cannot be loaded from the specified directory, startup fails. An empty value is treated as not set.
  • Host-provided assembly probe extensions (bundle probe, external assembly probe) still run first. It is the on-disk lookup and the bundle-extraction fallback that are replaced by the property.

cc @dotnet/appmodel @AaronRobinsonMSFT

Note

This PR was authored with assistance from GitHub Copilot.

elinor-fung and others added 2 commits May 28, 2026 16:19
Adds a new well-known host runtime property, SYSTEM_CORELIB_DIRECTORY, that lets
a host explicitly specify the directory containing System.Private.CoreLib.dll.
When set, the runtime loads CoreLib from this directory instead of the default
lookup beside coreclr, and the single-file bundle-extraction fallback is also
skipped.

This restores a path-discovery mechanism for hosts (notably mobile platforms
like iOS) where CoreCLR is statically linked into the host executable and
CoreLib is not located beside it. PR dotnet#128278 removed the previous TPA-scanning
fallback in BindToSystem; this replaces it with an explicit, opt-in contract
rather than implicit scanning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a Loader test that exercises the new SYSTEM_CORELIB_DIRECTORY host
runtime property: copy System.Private.CoreLib.dll into a subdirectory,
point the property at that directory, and assert typeof(object).Assembly.Location
resolves to the configured directory (and is not the default location beside
coreclr).

To make corerun usable for testing host-contract-driven features, also
extend its host_runtime_contract::get_runtime_property implementation
to look up user-defined properties passed via -p/--property. Previously
those only flowed to coreclr_initialize (visible via AppContext) but
were not exposed through the host runtime contract, so calls to
HostInformation::GetProperty from native code returned no value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 an explicit SYSTEM_CORELIB_DIRECTORY host runtime property so CoreCLR hosts can direct the runtime to load System.Private.CoreLib.dll from a known directory when it is not located beside coreclr.

Changes:

  • Adds the new well-known host property definition and documentation.
  • Updates CoreCLR system assembly binding to honor the host-provided CoreLib directory and skip the extraction fallback for that path.
  • Extends corerun property lookup and adds a Loader test validating the successful override path.
Show a summary per file
File Description
src/native/corehost/host_runtime_contract.h Defines the new SYSTEM_CORELIB_DIRECTORY host property.
src/coreclr/binder/assemblybindercommon.cpp Uses the host property to choose the CoreLib lookup directory and gate fallback behavior.
src/coreclr/hosts/corerun/corerun.cpp Makes -p/--property values visible through the host runtime contract callback.
src/tests/Loader/SystemCoreLibDirectory/SystemCoreLibDirectory.csproj Adds the test project setup, host property, and CoreLib copy precommands.
src/tests/Loader/SystemCoreLibDirectory/SystemCoreLibDirectory.cs Verifies CoreLib is loaded from the configured subdirectory.
docs/design/features/host-runtime-information.md Documents the new well-known runtime property.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 3

Comment thread docs/design/features/host-runtime-information.md Outdated
Comment thread src/coreclr/binder/assemblybindercommon.cpp Outdated
Comment thread src/coreclr/binder/assemblybindercommon.cpp
@vitek-karas
Copy link
Copy Markdown
Member

Just curious why "Directory" why not file path? But now I realize we probably don't want to allow anything to provide a file which is NOT called System.Private.CoreLib.

@vitek-karas
Copy link
Copy Markdown
Member

@rolfbjarne - for future iOS host changes.
@simonrozsival - FYI, I don't think we need this in Android.

@elinor-fung
Copy link
Copy Markdown
Member Author

Just curious why "Directory" why not file path? But now I realize we probably don't want to allow anything to provide a file which is NOT called System.Private.CoreLib.

Yep, that is exactly why I went with directory instead of path.

@elinor-fung elinor-fung added this to the 11.0.0 milestone May 29, 2026
Comment thread docs/design/features/host-runtime-information.md Outdated
Comment thread src/coreclr/binder/assemblybindercommon.cpp
Comment thread docs/design/features/host-runtime-information.md Outdated
Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 1, 2026 17:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new

@elinor-fung
Copy link
Copy Markdown
Member Author

/ba-g build analysis is stuck, but everything is green.

@elinor-fung elinor-fung merged commit b0f76ec into dotnet:main Jun 3, 2026
184 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Jun 3, 2026
@elinor-fung elinor-fung deleted the system-corelib-dir-prop branch June 3, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants