#1408·BepInEx

IL2CPP: preloader dies on Apple Silicon in ConsoleSetOutFix with an ILHook NullReferenceException

Author: cdobbynCreated Sep 21, 2026Updated Sep 21, 2026

What happened?

On Apple Silicon, BepInEx 6 IL2CPP dies in the preloader before it writes a log. ConsoleSetOutFix.Apply() throws HarmonyException: IL Compile Error, wrapping a NullReferenceException from MonoMod.RuntimeDetour.ILHook..ctor. The same build under Rosetta gets all the way to Runtime invoke patched.

This is the CoreCLR twin of #1303, which #1402 fixed for v5 on Mono. There, DetourHelper.Runtime stayed null because the detour platform constructor threw once and get_Runtime caches that result. The stack here is the same shape, so I suspect the same root cause with a different detour platform underneath.

I have not diagnosed which platform MonoMod picks on arm64 CoreCLR, or why its constructor fails — only that the failure is reproducible and architecture-dependent on identical managed assemblies.

Filing rather than fixing because the v5 fix hinged on a specific mprotect/MAP_JIT interaction that I measured before patching, and I have not done that work for CoreCLR yet.

Steps to reproduce

  1. Kingdom Two Crowns 2.4.0, a universal macOS binary, Unity 6000.0.61f1, IL2CPP metadata v31.
  2. Install BepInEx 6 IL2CPP with #1407 applied, an arm64 libdobby.dylib (BepInEx/Dobby#16) and an arm64 .NET 6.0.7 runtime in dotnet/.
  3. Launch through run_bepinex.sh, which sets ARCHPREFERENCE="arm64,x86_64" so the universal binary runs native.
  4. No LogOutput.log appears. A preloader_<date>.log is written beside the executable.
  5. Relaunch with ARCHPREFERENCE="x86_64,arm64". Everything below runs fine.

Without #1407 this is unreachable: Paths.SetExecutablePath throws first, on both architectures.

BepInEx Distribution

Bleeding Edge from BepisBuilds

Log outputs

txt
HarmonyLib.HarmonyException: IL Compile Error (unknown location)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoMod.RuntimeDetour.ILHook..ctor(MethodBase from, Manipulator manipulator, ILHookConfig& config)
   at MonoMod.RuntimeDetour.ILHook..ctor(MethodBase from, Manipulator manipulator, ILHookConfig config)
   at HarmonyLib.Public.Patching.ManagedMethodPatcher.DetourTo(MethodBase replacement)
   at HarmonyLib.PatchFunctions.UpdateWrapper(MethodBase original, PatchInfo patchInfo)
   --- End of inner exception stack trace ---
   at HarmonyLib.PatchClassProcessor.ReportException(Exception exception, MethodBase original)
   at HarmonyLib.PatchClassProcessor.Patch()
   at HarmonyLib.Harmony.PatchAll(Type type)
   at HarmonyLib.Harmony.CreateAndPatchAll(Type type, String harmonyInstanceId)
   at BepInEx.Preloader.RuntimeFixes.ConsoleSetOutFix.Apply() in BepInEx.Preloader.Core/RuntimeFixes/ConsoleSetOutFix.cs:line 18
   at BepInEx.Unity.IL2CPP.Preloader.Run() in Runtimes/Unity/BepInEx.Unity.IL2CPP/Preloader.cs:line 28
   at BepInEx.Unity.IL2CPP.UnityPreloaderRunner.PreloaderMain() in Runtimes/Unity/BepInEx.Unity.IL2CPP/UnityPreloadRunner.cs:line 27

Same build, same game, ARCHPREFERENCE="x86_64,arm64":

txt
[Message:   BepInEx] Chainloader initialized
[Debug  : Preloader] Runtime invoke pointer: 0x132569130
[Debug  : Preloader] Runtime invoke patched

Environment

markdown
- OS: macOS 15 (kernel 26.6.2), Apple Silicon
- Game: Kingdom Two Crowns 2.4.0, universal binary (x86_64 + arm64)
- Unity: 6000.0.61f1, IL2CPP, metadata v31
- BepInEx: 6.0.0-be.788+5b766a3, plus #1407
- Runtime: .NET 6.0.7, osx-arm64
- Doorstop: 4.5.0 universal
- Dobby: arm64, built per BepInEx/Dobby#16

Related

  • #1303 and #1402 — the same failure shape on v5 / Mono, already fixed
  • #899 — native Apple Silicon support, the umbrella issue
  • #1407 — the macOS path fixes needed to reach this code at all
  • #1403 — a separate arm64 defect, FollowExportThunks decoding x86 on arm64
  • BepInEx/Dobby#16 — the arm64 libdobby.dylib this needs