{"record":{"id":"088580e02ca857f1","repo":"OpenRA/OpenRA","slug":"could-not-load-hostfxr-run-app-s","errorCode":null,"errorMessage":"Could not load hostfxr_run_app(): %s\n","messagePattern":"Could not load hostfxr_run_app\\(\\): (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packaging/macos/apphost.c","lineNumber":58,"sourceCode":"{\n\tvoid *lib = dlopen(argv[1], RTLD_LAZY);\n\tif (lib == NULL)\n\t{\n\t\tfprintf(stderr, \"Failed to load %s: %s\\n\", argv[1], dlerror());\n\t\treturn 1;\n\t}\n\n\thostfxr_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\");\n\tif (!hostfxr_initialize_for_dotnet_command_line)\n\t{\n\t\tfprintf(stderr, \"Could not load hostfxr_initialize_for_dotnet_command_line(): %s\\n\", dlerror());\n\t\treturn 1;\n\t}\n\n\thostfxr_run_app_fn hostfxr_run_app = (hostfxr_run_app_fn)dlsym(lib, \"hostfxr_run_app\");\n\tif (!hostfxr_run_app)\n\t{\n\t\tfprintf(stderr, \"Could not load hostfxr_run_app(): %s\\n\", dlerror());\n\t\treturn 1;\n\t}\n\n\thostfxr_close_fn hostfxr_close = (hostfxr_close_fn)dlsym(lib, \"hostfxr_close\");\n\tif (!hostfxr_close)\n\t{\n\t\tfprintf(stderr, \"Could not load hostfxr_close(): %s\\n\", dlerror());\n\t\treturn 1;\n\t}\n\n\tstruct hostfxr_initialize_parameters params;\n\tparams.size = sizeof(params);\n\tparams.host_path = argv[0];\n\tparams.dotnet_root = dirname(argv[1]);\n\n\thostfxr_handle host_context_handle;\n\thostfxr_initialize_for_dotnet_command_line(\n\t    argc - 2,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/OpenRA/OpenRA/blob/a520984d91eda9de48a62b1d15c1e3bad0d4fb1a/packaging/macos/apphost.c#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: incomplete hostfxr lacks run_app\nhostfxr_run_app = dlsym(lib, \"hostfxr_run_app\"); // NULL\n\n// after: ship the full matching runtime\n$ nm -gU OpenRA.app/Contents/MacOS/libhostfxr.dylib | grep hostfxr_run_app\n000000000000abcd T hostfxr_run_app   // present\n$ dotnet publish -r osx-arm64 --self-contained   // bundles complete hostfxr","handlingStrategy":"validation","validationCode":"// Packaging-time symbol check (fail fast, not at user runtime):\n// nm -gU libhostfxr.dylib | grep -q hostfxr_run_app || { echo 'hostfxr missing run_app'; exit 1; }","typeGuard":null,"tryCatchPattern":"if (!hostfxr_run_app) {\n    fprintf(stderr, \"Loaded hostfxr is incomplete (no run_app). Re-bundle the full matching .NET runtime.\\n\");\n    dlclose(lib);\n    return 1;\n}","preventionTips":["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."],"tags":["macos","dotnet","apphost","hostfxr","abi","packaging"],"backgroundTag":null,"analyzedSha":"a520984d91eda9de48a62b1d15c1e3bad0d4fb1a","analyzedAt":"2026-08-13T15:30:14.787Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}