You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] saveable discovery calls can crash the first save load (0x80131506) #369
On IL2CPP, the first save load of a session can end the game with Fatal error. Internal CLR error. (0x80131506) and no managed exception. Crash dumps show it inside S1API's saveable discovery:
Which assembly.DiscoverSaveableTypes runs unoptimised, so its loop index is still on the stack. In every dump, mapped against the loaded-assembly list, it points at MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll, the generated interop assembly. The method filters assemblies by FullName prefix (System, Unity, mscorlib, netstandard, Microsoft, Il2Cpp, MelonLoader, 0Harmony). Assembly-CSharp and Assembly-CSharp-firstpass match none of them, so both are enumerated on every IL2CPP game.
How often. Whether a given mod set dies there varies from run to run. On one 0.4.7f12 setup with S1API 3.2.1, hosting a lobby and loading a save died in 13 of 16 runs. Removing other mods only changed the rate; every dump still pointed at Assembly-CSharp.dll. This matches the 0x80131506 in #289, which bounded the NPC discovery paths through ReflectionUtils.GetDerivedClasses but did not touch this one.
Same pattern elsewhere.ProductEffectPatches.GetNpcWrapperTypeById walks every loaded assembly with no filter.
Suggested fix. Route both through ReflectionUtils.GetDerivedClasses<T>(). A direct Saveable subclass and an NPC wrapper both have to reference S1API, so the results do not change.
This suggests the crash occurs during product-effect processing after a successful sale, when S1API attempts to discover an NPC wrapper type.
The affected NPC was a vanilla NPC, and the product was ordinary cocaine. I was not interacting with a Drug Runners employee (from the Drug Runners mod) or using a custom product.
The attached console screenshot shows the fatal error and stack trace. The accompanying log is my Latest.log generated by MelonLoader.
changed the title [-]IL2CPP: saveable discovery calls GetTypes() on Assembly-CSharp and can crash the first save load (0x80131506)[/-][+][BUG] saveable discovery calls can crash the first save load (0x80131506)[/+]on Oct 16, 2026
Thanks for the extra repro. I tested a vanilla cocaine sale to Kyle Cooley on 0.4.7f12 IL2CPP. On S1API 3.2.1, the sale reached the Assembly-CSharp scan all three times, but the game kept running. PR #370 completed the sale twice without scanning those assemblies.
I’m leaving this open since I can’t reproduce the fatal CLR error locally. We’d need a reproducible mod setup, or a smaller Polyfill repro, to figure out what makes that scan crash before calling it fixed.
I'm going to check to see if it was just the one NPC to whom I sold it that could be the issue, or if I can reproduce the crash by selling to other customers. If it doesn't crash for other NPCs, I'll comment the name of the one NPC for whom it did. I don't know how helpful that will be, but I'll also throw in the latest log generated from that with that comment!
In the first log that I've shared, I made the cocaine deal with Herbert Bleuball, and then the fatal error occurred. In this one, I sold to Fiona Hancock, and the same error happened in the same way I described with Herbert. Here are my logs for what happened with Fiona:
Activity
LoganaterGames commentedon Oct 16, 2026
Additional reproduction case: Fatal CLR error after selling cocaine to a vanilla NPC
Game: Schedule I 0.4.7f12
Unity: 2022.3.62f2
Mod loader: MelonLoader 0.7.3 Open-Beta
S1API: Forked v3.2.1
I encountered this fatal crash while selling normal cocaine to a vanilla NPC.
Steps to reproduce:
Fatal error:
Fatal error. Internal CLR error. (0x80131506)The stack trace in the console screenshot contains the following calls:
System.Reflection.RuntimeModule.GetTypes(System.Reflection.RuntimeModule)System.Reflection.Assembly.GetTypes()S1API.Internal.Patches.ProductEffectPatches.GetNpcWrapperTypeById()S1API.Internal.Patches.ProductEffectPatches.ResolveApiNpc(...)S1API.Internal.Patches.ProductEffectPatches.ProductEffects_Prefix(...)ProductItemInstance.ApplyEffectsToNPC(...)This suggests the crash occurs during product-effect processing after a successful sale, when S1API attempts to discover an NPC wrapper type.
The affected NPC was a vanilla NPC, and the product was ordinary cocaine. I was not interacting with a Drug Runners employee (from the Drug Runners mod) or using a custom product.
The attached console screenshot shows the fatal error and stack trace. The accompanying log is my
Latest.loggenerated by MelonLoader.Latest.log
This may provide an additional reproduction path for the unsafe assembly scanning described in this issue and addressed by pull request #370.
[-]IL2CPP: saveable discovery calls GetTypes() on Assembly-CSharp and can crash the first save load (0x80131506)[/-][+][BUG] saveable discovery calls can crash the first save load (0x80131506)[/+]ifBars commentedon Oct 16, 2026
Thanks for the extra repro. I tested a vanilla cocaine sale to Kyle Cooley on 0.4.7f12 IL2CPP. On S1API 3.2.1, the sale reached the
Assembly-CSharpscan all three times, but the game kept running. PR #370 completed the sale twice without scanning those assemblies.I’m leaving this open since I can’t reproduce the fatal CLR error locally. We’d need a reproducible mod setup, or a smaller Polyfill repro, to figure out what makes that scan crash before calling it fixed.
LoganaterGames commentedon Oct 16, 2026
I'm going to check to see if it was just the one NPC to whom I sold it that could be the issue, or if I can reproduce the crash by selling to other customers. If it doesn't crash for other NPCs, I'll comment the name of the one NPC for whom it did. I don't know how helpful that will be, but I'll also throw in the latest log generated from that with that comment!
LoganaterGames commentedon Oct 17, 2026
In the first log that I've shared, I made the cocaine deal with Herbert Bleuball, and then the fatal error occurred. In this one, I sold to Fiona Hancock, and the same error happened in the same way I described with Herbert. Here are my logs for what happened with Fiona:
Latest.log
I hope these help in some way; I feel like I can't sell to anyone personally unless it's through my dealers. Your mods are amazing, ifBars!!