pardeike/Harmony · error · ArgumentNullException
Value cannot be null. (Parameter 'config.original')
Error message
Value cannot be null. (Parameter 'config.original')
What it means
MethodCreator's constructor requires a MethodCreatorConfig whose 'original' (the method being replaced/wrapped) is non-null. This is an internal guard hit when the wrapper-generation pipeline is invoked without a resolved original method — almost always downstream of a null patch target that earlier code let through. It surfaces as ArgumentNullException with parameter name 'config.original'.
Solutions
- Validate the patch target is non-null before calling harmony.Patch/PatchProcessor/ReversePatch
- Fix the reflection/AccessTools lookup so it resolves the intended method
- Log the exact target type+name in your patch bootstrap so null resolution fails loudly at startup
Example fix
// before
var original = AccessTools.Method(typeof(Hud), "Render");
harmony.Patch(original, postfix: postfix); // original may be null
// after
var original = AccessTools.Method(typeof(Hud), "Render") ?? throw new InvalidOperationException("Hud.Render not found");
harmony.Patch(original, postfix: postfix); Defensive patterns
Strategy: validation
Validate before calling
if (original is null)
throw new InvalidOperationException($"Refusing to patch: original method not found ({type}.{name})"); Type guard
static MethodBase EnsureTarget(MethodBase? m, string name) =>
m ?? throw new InvalidOperationException($"Patch target '{name}' not found"); Try / catch
try { harmony.Patch(original, prefix: prefix); }
catch (ArgumentNullException ex) when (ex.ParamName == "config.original")
{ Log.Error("Patch target was null — check your reflection lookup"); } Prevention
- Assert all patch targets resolve during mod/plugin startup, before gameplay
- Use AccessTools and log AccessTools.FailureInfo when a lookup fails
- Avoid caching MethodBase across hot reloads
- Fail loudly at boot rather than letting null flow into Harmony internals
When it happens
Trigger: Internal wrapper/patch creation where config.original was never set because the MethodBase resolution returned null; calling Harmony patching APIs with a null original MethodInfo that bypassed earlier null guards.
Common situations: Mods patching methods found by reflection that no longer exist after a game update; reverse-patch attempts against a null source method; stale cached method references across hot reloads.
Related errors
- Value cannot be null. (Parameter 'fromMethod')
- Value cannot be null. (Parameter 'method')
- The type must declare an empty constructor (the constructor…
- Value cannot be null. (Parameter 'config.methodbase')
- Value cannot be null. (Parameter 'generator')
AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15).
Data as JSON: /api/errors/4fd1b44474e6dd62.
Report an issue: GitHub.
Appendix: source
Thrown at Harmony/Internal/MethodCreator.cs:18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using static HarmonyLib.Code;
namespace HarmonyLib
{
internal class MethodCreator
{
internal MethodCreatorConfig config;
internal MethodCreator(MethodCreatorConfig config)
{
if (config.original is null)
throw new ArgumentNullException("config.original");
this.config = config;
if (config.debug)
{
FileLog.LogBuffered($"### Patch: {config.original.FullDescription()}");
FileLog.FlushBuffer();
}
if (config.Prepare() == false)
throw new Exception("Could not create replacement method");
}
internal (MethodInfo, Dictionary<int, CodeInstruction>) CreateReplacement()
{
config.originalVariables = this.DeclareOriginalLocalVariables(config.MethodBase);
config.localVariables = new VariableState();
if (config.Fixes.Any() && config.returnType != typeof(void))
{
config.resultVariable = config.DeclareLocal(config.returnType);
View on GitHub (pinned to e7872dc170)