OpenRA/OpenRA · critical
Could not load hostfxr_run_app(): %s
Error message
Could not load hostfxr_run_app(): %s
What it means
Printed by the macOS apphost when dlsym(lib, "hostfxr_run_app") returns NULL. hostfxr_initialize_for_dotnet_command_line resolved successfully, so the library is recognizably hostfxr, but it does not export the run_app entrypoint — indicating a partial, stub, or ABI-incompatible hostfxr. dlerror() gives the loader's 'symbol not found' detail.
Source
Thrown at packaging/macos/apphost.c:58
{
void *lib = dlopen(argv[1], RTLD_LAZY);
if (lib == NULL)
{
fprintf(stderr, "Failed to load %s: %s\n", argv[1], dlerror());
return 1;
}
hostfxr_initialize_for_dotnet_command_line_fn hostfxr_initialize_for_dotnet_command_line = (hostfxr_initialize_for_dotnet_command_line_fn)dlsym(lib, "hostfxr_initialize_for_dotnet_command_line");
if (!hostfxr_initialize_for_dotnet_command_line)
{
fprintf(stderr, "Could not load hostfxr_initialize_for_dotnet_command_line(): %s\n", dlerror());
return 1;
}
hostfxr_run_app_fn hostfxr_run_app = (hostfxr_run_app_fn)dlsym(lib, "hostfxr_run_app");
if (!hostfxr_run_app)
{
fprintf(stderr, "Could not load hostfxr_run_app(): %s\n", dlerror());
return 1;
}
hostfxr_close_fn hostfxr_close = (hostfxr_close_fn)dlsym(lib, "hostfxr_close");
if (!hostfxr_close)
{
fprintf(stderr, "Could not load hostfxr_close(): %s\n", dlerror());
return 1;
}
struct hostfxr_initialize_parameters params;
params.size = sizeof(params);
params.host_path = argv[0];
params.dotnet_root = dirname(argv[1]);
hostfxr_handle host_context_handle;
hostfxr_initialize_for_dotnet_command_line(
argc - 2,View on GitHub (pinned to a520984d91)
Solutions
- Confirm the export set: `nm -gU libhostfxr.dylib | grep hostfxr_run_app` — absence confirms an incomplete/wrong hostfxr.
- Replace the dylib with the matching libhostfxr.dylib from the same .NET runtime version the app was published against.
- Repackage the app via `dotnet publish` so runtime + hostfxr + apphost are consistent.
- Verify file integrity (not truncated) with `codesign --verify` and `file`/`otool -L`.
- If building custom hostfxr, ensure the full public hostfxr API (incl. hostfxr_run_app) is exported.
Example fix
// before: incomplete hostfxr lacks run_app hostfxr_run_app = dlsym(lib, "hostfxr_run_app"); // NULL // after: ship the full matching runtime $ nm -gU OpenRA.app/Contents/MacOS/libhostfxr.dylib | grep hostfxr_run_app 000000000000abcd T hostfxr_run_app // present $ dotnet publish -r osx-arm64 --self-contained // bundles complete hostfxr
Defensive patterns
Strategy: validation
Validate before calling
// Packaging-time symbol check (fail fast, not at user runtime):
// nm -gU libhostfxr.dylib | grep -q hostfxr_run_app || { echo 'hostfxr missing run_app'; exit 1; } Try / catch
if (!hostfxr_run_app) {
fprintf(stderr, "Loaded hostfxr is incomplete (no run_app). Re-bundle the full matching .NET runtime.\n");
dlclose(lib);
return 1;
} Prevention
- Use `--self-contained` publish so the complete hostfxr is bundled.
- Add a CI gate that nm-verifies all three hostfxr entrypoints after packaging.
- Do not strip/minimize hostfxr exports.
- Keep apphost typedefs in sync with the bundled runtime version.
When it happens
Trigger: A hostfxr build/variant that omits hostfxr_run_app (e.g. a minimal or wrong runtime pack); ABI drift where run_app was renamed/removed; loading a hostpolicy stub instead of the full hostfxr.
Common situations: Shipping a trimmed/wrong runtime pack that lacks run_app; bundling hostfxr from a preview/SDK build whose export set differs; corrupt or truncated dylib that resolves some symbols but not others.
Related errors
- Could not load hostfxr_initialize_for_dotnet_command_line():
- Could not load hostfxr_close(): %s
- Failed to load %s: %s
AI-assisted analysis of OpenRA/OpenRA@a520984d91 (2026-08-13).
Data as JSON: /api/errors/088580e02ca857f1.
Report an issue: GitHub.