Skip to content

[net11.0] [runtime] Register host_runtime_contract callbacks so CoreCLR finds System.Private.CoreLib.dll#25562

Merged
rolfbjarne merged 4 commits into
darc-net11.0-d4fe64b2-8391-403d-bbd7-5e3371f43b46from
dev/kotlarmilos/fix-25542-coreclr-corelib-fallback
May 28, 2026
Merged

[net11.0] [runtime] Register host_runtime_contract callbacks so CoreCLR finds System.Private.CoreLib.dll#25562
rolfbjarne merged 4 commits into
darc-net11.0-d4fe64b2-8391-403d-bbd7-5e3371f43b46from
dev/kotlarmilos/fix-25542-coreclr-corelib-fallback

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

Description

When CoreCLR starts, AssemblyBinderCommon::BindToSystem loads System.Private.CoreLib.dll. It first looks next to libcoreclr, and if that fails it runs a fallback path. In .NET 11 preview 5, dotnet/runtime#128278 changed the fallback to read CoreLib from the single-file bundle's extraction directory, and gated it on Bundle::AppIsBundle() && Bundle::AppBundle->HasExtractedFiles().

Those two flags are set from the host. AppIsBundle() requires the host to register a bundle_probe callback on host_runtime_contract, and HasExtractedFiles() requires the host to return a path from the BUNDLE_EXTRACTION_PATH runtime property. The primary lookup fails on Apple mobile device, because libcoreclr ships inside Frameworks/libcoreclr.framework/libcoreclr while System.Private.CoreLib.dll lives at the app bundle root, so CoreLib is never next to libcoreclr.

Fix

Register a no-op bundle_probe and provide BUNDLE_EXTRACTION_PATH with the directory containing System.Private.CoreLib.dll (app bundle root, then .xamarin/), so the gate passes and BindToSystem resolves CoreLib from that directory.

Fixes #25542

…ystem.Private.CoreLib.dll

dotnet/runtime#128278 (.NET 11 preview 5) gated the BindToSystem CoreLib
fallback behind `Bundle::AppIsBundle () && Bundle::AppBundle->HasExtractedFiles ()`.
macios doesn't bundle assemblies and never registered `bundle_probe` nor a
`BUNDLE_EXTRACTION_PATH` property, so the gate fails and CoreCLR can't locate
`System.Private.CoreLib.dll` (which lives at the app bundle root, not next to
`libcoreclr.framework/libcoreclr`). The app aborts in `xamarin_vm_initialize`
with "Failed to initialize the VM".

Fix: register a no-op `bundle_probe` so `Bundle::AppBundle` is non-null, and
answer `BUNDLE_EXTRACTION_PATH` from `get_runtime_property` with the directory
that actually contains CoreLib (app bundle root, then `.xamarin/<RID>`, matching
the TPA probe order). The fallback then finds CoreLib and the VM initializes.

Fixes #25542.

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 updates the Apple native CoreCLR host shim to provide the host_runtime_contract callbacks CoreCLR now relies on (in .NET 11 preview 5+) to locate System.Private.CoreLib.dll via the bundle/extraction fallback, fixing CoreCLR startup failures on iOS devices where libcoreclr and CoreLib are not colocated.

Changes:

  • Register a no-op bundle_probe callback so CoreCLR considers the app “bundled” for the fallback gate.
  • Implement get_runtime_property to answer HOST_PROPERTY_BUNDLE_EXTRACTION_PATH with the directory that actually contains System.Private.CoreLib.dll (bundle root, then .xamarin/<RID>).
  • Wire these callbacks into the host_runtime_contract passed through HOST_RUNTIME_CONTRACT during xamarin_vm_initialize.

Comment thread runtime/runtime.m Outdated
Comment thread runtime/runtime.m Outdated
Comment thread runtime/runtime.m Outdated
kotlarmilos and others added 3 commits May 28, 2026 09:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #0a31d6e] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 0a31d6e20ad6c1e154ac761d43cd949d81a1c29d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 0a31d6e20ad6c1e154ac761d43cd949d81a1c29d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #0a31d6e] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 0a31d6e20ad6c1e154ac761d43cd949d81a1c29d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #0a31d6e] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 0a31d6e20ad6c1e154ac761d43cd949d81a1c29d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🔥 [CI Build #0a31d6e] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

3 tests crashed, 24 tests failed, 132 tests passed.

Failures

❌ dotnettests tests (MacCatalyst)

🔥 Failed catastrophically on VSTS: test results - dotnettests_maccatalyst (no summary found).

Html Report (VSDrops) Download

❌ linker tests (macOS)

🔥 Failed catastrophically on VSTS: test results - linker_macos (no summary found).

Html Report (VSDrops) Download

❌ monotouch tests (iOS) [attempt 2]

24 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug: LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (CoreCLR): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (CoreCLR, ARM64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (CoreCLR, x64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (CoreCLR, Universal): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (link sdk): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (link all): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (LinkSdk): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (static registrar): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (all optimizations): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (ARM64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (NativeAOT, ARM64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT, ARM64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (managed static registrar): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (trimmable static registrar): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, all optimizations): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (NativeAOT, x64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT, x64): LaunchTimedOut
  • monotouch-test/iOS - simulator/Debug (interpreter): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (interpreter): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (strict inline dlfcn, link sdk): LaunchTimedOut
  • monotouch-test/iOS - simulator/Release (NativeAOT, .NET 11 defaults): LaunchTimedOut

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst) [attempt 2]

🔥 Failed catastrophically on VSTS: test results - monotouch_maccatalyst (no summary found).

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 9 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 24 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 0a31d6e20ad6c1e154ac761d43cd949d81a1c29d [PR build]

@rolfbjarne
Copy link
Copy Markdown
Member Author

Merging, this targets another PR, and the problem this PR is supposed to fix looks fixed.

@rolfbjarne rolfbjarne merged commit c6fabd7 into darc-net11.0-d4fe64b2-8391-403d-bbd7-5e3371f43b46 May 28, 2026
45 of 53 checks passed
rolfbjarne added a commit that referenced this pull request May 28, 2026
…LR finds System.Private.CoreLib.dll (#25562)

### Description

When CoreCLR starts, AssemblyBinderCommon::BindToSystem loads
System.Private.CoreLib.dll. It first looks next to libcoreclr, and if
that fails it runs a fallback path. In .NET 11 preview 5,
dotnet/runtime#128278 changed the fallback to read CoreLib from the
single-file bundle's extraction directory, and gated it on
Bundle::AppIsBundle() && Bundle::AppBundle->HasExtractedFiles().

Those two flags are set from the host. AppIsBundle() requires the host
to register a bundle_probe callback on host_runtime_contract, and
HasExtractedFiles() requires the host to return a path from the
BUNDLE_EXTRACTION_PATH runtime property. The primary lookup fails on
Apple mobile device, because libcoreclr ships inside
Frameworks/libcoreclr.framework/libcoreclr while
System.Private.CoreLib.dll lives at the app bundle root, so CoreLib is
never next to libcoreclr.

### Fix

Register a no-op bundle_probe and provide BUNDLE_EXTRACTION_PATH with
the directory containing System.Private.CoreLib.dll (app bundle root,
then .xamarin/<RID>), so the gate passes and BindToSystem resolves
CoreLib from that directory.

Fixes #25542

---------

Co-authored-by: Milos Kotlar <miloskotlar@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Milos Kotlar <kotlarmilos@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants