Skip to content

[runtime] Register host_runtime_contract callbacks so CoreCLR finds System.Private.CoreLib.dll#25561

Closed
kotlarmilos wants to merge 4 commits into
net11.0from
dev/kotlarmilos/fix-25542-coreclr-corelib-fallback
Closed

[runtime] Register host_runtime_contract callbacks so CoreCLR finds System.Private.CoreLib.dll#25561
kotlarmilos wants to merge 4 commits into
net11.0from
dev/kotlarmilos/fix-25542-coreclr-corelib-fallback

Conversation

@kotlarmilos
Copy link
Copy Markdown
Member

@kotlarmilos kotlarmilos commented May 28, 2026

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>
@kotlarmilos kotlarmilos marked this pull request as ready for review May 28, 2026 07:26
@kotlarmilos kotlarmilos requested a review from rolfbjarne as a code owner May 28, 2026 07:26
Copilot AI review requested due to automatic review settings May 28, 2026 07:26
@kotlarmilos kotlarmilos self-assigned this May 28, 2026
@kotlarmilos kotlarmilos added this to the .NET 11 milestone May 28, 2026
@rolfbjarne
Copy link
Copy Markdown
Member

@kotlarmilos I created a PR from your branch into the maestro PR that brings this change from dotnet/runtime, that way we can be sure it works: #25562

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 CoreCLR startup path so the host runtime contract can satisfy CoreCLR’s new CoreLib fallback lookup requirements on Apple app bundle layouts.

Changes:

  • Adds CoreCLR host contract callbacks for bundle_probe and BUNDLE_EXTRACTION_PATH.
  • Computes the directory containing System.Private.CoreLib.dll from the app bundle root or .xamarin/<RID>.
  • Registers the new callbacks in xamarin_vm_initialize.
Show a summary per file
File Description
runtime/runtime.m Adds CoreCLR host runtime contract callbacks and wires them into VM initialization.

Copilot's findings

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

Comment thread runtime/runtime.m Outdated
// Bundle::AppIsBundle () && Bundle::AppBundle->HasExtractedFiles (). Register a no-op
// bundle_probe so AppBundle is non-null, and answer BUNDLE_EXTRACTION_PATH with the
// directory containing System.Private.CoreLib.dll so the fallback finds it.
static bool xamarin_coreclr_bundle_probe(const char *path, int64_t *offset, int64_t *size, int64_t *compressed_size)
Comment thread runtime/runtime.m Outdated
Comment on lines +2471 to +2476
static bool xamarin_coreclr_bundle_probe(const char *path, int64_t *offset, int64_t *size, int64_t *compressed_size)
{
return false;
}

static const char *xamarin_compute_corelib_directory(void)
Comment thread runtime/runtime.m Outdated
return cached;
}

static size_t xamarin_coreclr_get_runtime_property(const char *key, char *value_buffer, size_t value_buffer_size, void *contract_context)
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>
@kotlarmilos
Copy link
Copy Markdown
Member Author

Closing in favor of #25562

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

🔥 [PR Build #$(fix_c] Build failed (Build packages) 🔥

Build failed for the job 'Build packages' (with job status 'Failed')

Pipeline on Agent
Hash: $(fix_commit.GIT_HASH) [PR build]

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.

4 participants