Skip to content

NullReferenceException on Android — AccessTools.Method(typeof(SeedShop), "draw") returns null #9

Description

@wanda2009

Environment:

  • Stardew Valley 1.6.15.3 (build 26177) on Android
  • SMAPI v4.3.2.4
  • CustomBackpackFramework v1.2.0

Bug:
The mod crashes on entry with this error:

[ERROR The Return of Custom Backpack Framework] Mod crashed on entry and might not work correctly. Technical details:
AggregateException: One or more errors occurred. (Null method for platinummyr.CustomBackpackFramework)
---> NullReferenceException: Null method for platinummyr.CustomBackpackFramework
at HarmonyLib.PatchProcessor.Patch()
at HarmonyLib.Harmony.Patch(...)
at CustomBackpack.ModEntry.Entry(IModHelper helper)

Root cause:
In ModEntry.cs, this patch call:

harmony.Patch(
original: AccessTools.Method(typeof(SeedShop), nameof(SeedShop.draw)),
prefix: new HarmonyMethod(typeof(ObjectPatches), nameof(ObjectPatches.SeedShop_draw_Prefix))
);

AccessTools.Method(typeof(SeedShop), "draw") returns null on the Android build — likely because SeedShop.draw doesn't exist or has a different signature on mobile. Passing original: null into harmony.Patch() throws immediately, aborting Entry() before any other patches or the mod's actual functionality get applied.

Suggested fix:
Guard this specific patch with a null check so it doesn't abort the whole Entry() method on platforms where SeedShop.draw isn't found:

var seedShopDraw = AccessTools.Method(typeof(SeedShop), nameof(SeedShop.draw));
if (seedShopDraw != null)
{
harmony.Patch(
original: seedShopDraw,
prefix: new HarmonyMethod(typeof(ObjectPatches), nameof(ObjectPatches.SeedShop_draw_Prefix))
);
}
else
{
Monitor.Log("Skipped SeedShop.draw patch (method not found on this platform).", LogLevel.Warn);
}

Happy to test a build on Android if you put one together — thanks for maintaining this mod!

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions