Skip to content

[BUG] saveable discovery calls can crash the first save load (0x80131506) #369

Open

Description

@DooDesch

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:

System.Reflection.RuntimeModule.GetTypes()
System.Reflection.Assembly.GetTypes()
S1API.Saveables.SaveableAutoRegistry.DiscoverSaveableTypes()
S1API.Saveables.SaveableAutoRegistry.GetRegisteredSaveables()
S1API.Internal.Patches.GenericSaveablesPatches.BeforeBaseLoaders(Il2CppScheduleOne.Persistence.LoadRequest)

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.

Activity

  1. LoganaterGames commented on Oct 16, 2026

    @LoganaterGames

    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:

    1. Interact with a vanilla NPC and open the normal product-selling menu.
    2. Provide the cocaine the NPC requested.
    3. Click Sell.
    4. The menu closes normally, as expected.
    5. Shortly afterward, the game freezes and terminates with a fatal CLR error.

    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.log generated by MelonLoader.

    Image

    Latest.log

    This may provide an additional reproduction path for the unsafe assembly scanning described in this issue and addressed by pull request #370.

  2. 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
  3. added
    bugSomething isn't working
    saveablesNative game save system
    MediumEdge case bugs, etc
    on Oct 16, 2026
  4. ifBars commented on Oct 16, 2026

    @ifBars
    Owner

    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.

  5. LoganaterGames commented on Oct 16, 2026

    @LoganaterGames

    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!

  6. LoganaterGames commented on Oct 17, 2026

    @LoganaterGames

    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:

    Image

    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!!

  7. LoganaterGames commented on Oct 19, 2026

    @LoganaterGames

    I recently discovered that after I gave Benji some product to sell, the same fatal crash error occurred once he made a sale.

    Image

    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.

  8. ifBars commented on Oct 19, 2026

    @ifBars
    Owner

    @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.

  9. LoganaterGames commented on Oct 19, 2026

    @LoganaterGames

    I'll investigate which mod(s) are my problem mods, and I'll report back once I have exhausted my list!

  10. LoganaterGames commented on Oct 20, 2026

    @LoganaterGames

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    MediumEdge case bugs, etcbugSomething isn't workingnon-reproducibleUnable to reproducesaveablesNative game save system

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions