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:
I recently discovered that after I gave Benji some product to sell, the same fatal crash error occurred once he made a sale.
I followed him to his first sale after handing him the product to confirm. You can see his sale in the log where the CartelInfluenceEnhancements log is posted right before the crash.
I tested Herbert and Fiona with S1API 3.2.1 and Polyfill, including 0.13.15 from your log and the newer 0.13.19. All seven automated sales completed without the fatal crash. I haven't tested Benji's dealer-sale path yet.
I also found that Polyfill already patches S1API's saveable discovery to limit which assemblies it scans. That guard is present in both versions, though it doesn't cover the product-effect scan shown in your sale crash.
Since this has only been reproduced with Polyfill installed, I'm unlikely to merge a fix if Polyfill can fix the underlying problem. We still need a smaller mod setup that triggers it to help figure out what's missing from my reproduction. It's likely a combination of Polyfill, S1API, and one of your other mods you have.
I think I have found all of the problem mods. This is a little janky to explain, but I'll do my best. The mods in question are the following:
MoreEmployeeAssignments
MoreEmployees
MoreGuns (Forked)
MoreMoneyLaundering
PoliceResponseOverhaul
These mods all trigger the fatal error that we've been experiencing; however, not all of the time. This is the janky part: If I enable a single mod like MoreEmployeeAssignments or MoreGuns by itself without any of the other problem mods loaded, the game works perfectly fine. But then when I load any of the mods together, the game crashes with the fatal error. This is what loses me: After removing every mod added after the first, when I reopen the game and make a sale to an NPC, it crashes again with the fatal error, even though it worked fine before I added the second mod. The error disappears when I remove the first added mod, and I can't imagine why it does this. It kinda looks like this:
Load any one mod > start game and make sale > game works > close game and add any other second mod > start game and make sale > game crashes > remove the added second mod > start game and make sale > game crashes again > remove the added first mod > start game and make sale > everything works like normal again.
The only mod that consistently crashes the game on its own in my mod list is PoliceResponseOverhaul. It doesn't need to be coupled with any of the other 4 mods to cause a crash.
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!!
LoganaterGames commentedon Oct 19, 2026
I recently discovered that after I gave Benji some product to sell, the same fatal crash error occurred once he made a sale.
I followed him to his first sale after handing him the product to confirm. You can see his sale in the log where the CartelInfluenceEnhancements log is posted right before the crash.
ifBars commentedon Oct 19, 2026
@DooDesch @LoganaterGames
I tested Herbert and Fiona with S1API 3.2.1 and Polyfill, including 0.13.15 from your log and the newer 0.13.19. All seven automated sales completed without the fatal crash. I haven't tested Benji's dealer-sale path yet.
I also found that Polyfill already patches S1API's saveable discovery to limit which assemblies it scans. That guard is present in both versions, though it doesn't cover the product-effect scan shown in your sale crash.
Since this has only been reproduced with Polyfill installed, I'm unlikely to merge a fix if Polyfill can fix the underlying problem. We still need a smaller mod setup that triggers it to help figure out what's missing from my reproduction. It's likely a combination of Polyfill, S1API, and one of your other mods you have.
LoganaterGames commentedon Oct 19, 2026
I'll investigate which mod(s) are my problem mods, and I'll report back once I have exhausted my list!
LoganaterGames commentedon Oct 20, 2026
I think I have found all of the problem mods. This is a little janky to explain, but I'll do my best. The mods in question are the following:
MoreEmployeeAssignments
MoreEmployees
MoreGuns (Forked)
MoreMoneyLaundering
PoliceResponseOverhaul
These mods all trigger the fatal error that we've been experiencing; however, not all of the time. This is the janky part: If I enable a single mod like MoreEmployeeAssignments or MoreGuns by itself without any of the other problem mods loaded, the game works perfectly fine. But then when I load any of the mods together, the game crashes with the fatal error. This is what loses me: After removing every mod added after the first, when I reopen the game and make a sale to an NPC, it crashes again with the fatal error, even though it worked fine before I added the second mod. The error disappears when I remove the first added mod, and I can't imagine why it does this. It kinda looks like this:
Load any one mod > start game and make sale > game works > close game and add any other second mod > start game and make sale > game crashes > remove the added second mod > start game and make sale > game crashes again > remove the added first mod > start game and make sale > everything works like normal again.
The only mod that consistently crashes the game on its own in my mod list is PoliceResponseOverhaul. It doesn't need to be coupled with any of the other 4 mods to cause a crash.
Here is a log with my working mod list:
Latest.log