pardeike/Harmony · error · ArgumentException
Undefined target method for patch method
Error message
Undefined target method for patch method {patchMethod.info.method.FullDescription()} What it means
PatchWithAttributes resolves each annotated patch method's target via PatchMethodinfo.GetOriginalMethod(). When the target cannot be found (wrong type/name/argumentTypes, or the method was renamed/removed), Harmony throws this ArgumentException naming the offending patch method.
Solutions
- Verify the target type and member name exist at runtime with AccessTools.TypeByName/AccessTools.Method before patching
- Correct the class/type, method name, and argumentTypes in the [HarmonyPatch] attribute to match the current assembly
- For version-dependent targets, resolve with TargetMethod() and search candidates dynamically instead of hard-coded attributes
Example fix
// before
[HarmonyPatch(typeof(Player), "MoveTo", typeof(Vector3))]
// after
static MethodBase TargetMethod() =>
AccessTools.Method(typeof(Player), "MoveTo", new[] { typeof(Vector3) })
?? AccessTools.Method(typeof(Player), "MoveTo"); Defensive patterns
Strategy: validation
Validate before calling
var target = patchMethod.info.GetOriginalMethod();
if (target is null) throw new ArgumentException($"{patchMethod.info.method} does not resolve to a target"); Try / catch
try { harmony.PatchAll(); } catch (ArgumentException e) when (e.Message.StartsWith("Undefined target method")) { LogMissingTarget(e); } Prevention
- Smoke-test every [HarmonyPatch] target with AccessTools at startup
- Avoid hard-coding targets in fragile/assemblies that change between versions
- Check for IL2CPP/trimming metadata stripping before relying on attribute-based lookup
When it happens
Trigger: A [HarmonyPatch] attribute on a patch method references a type or member that does not exist at runtime (renamed, stripped by trimming/IL2CPP, wrong assembly version, wrong argumentTypes for overloads).
Common situations: Game/framework updates that renamed internal methods; targeting methods in optional dependencies; AOT/IL2CPP builds where reflection metadata was stripped; typos in target class or method names.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- The type must declare an empty constructor (the constructor…
- Value cannot be null. (Parameter 'fromMethod')
- Value cannot be null. (Parameter 'method')
- Value cannot be null. (Parameter 'config.original')
- Method has wrong return type (should be assignable to )
AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15).
Data as JSON: /api/errors/f12a515547462372.
Report an issue: GitHub.
Appendix: source
Thrown at Harmony/Public/PatchClassProcessor.cs:175
foreach (var job in jobs.GetJobs())
{
lastOriginal = job.original;
if (unpatch)
ProcessUnpatchJob(job);
else
ProcessPatchJob(job);
}
return jobs.GetReplacements();
}
List<MethodInfo> PatchWithAttributes(ref MethodBase lastOriginal, bool unpatch)
{
var jobs = new PatchJobs<MethodInfo>();
foreach (var patchMethod in patchMethods)
{
lastOriginal = patchMethod.info.GetOriginalMethod();
if (lastOriginal is null)
throw new ArgumentException($"Undefined target method for patch method {patchMethod.info.method.FullDescription()}");
var job = jobs.GetJob(lastOriginal);
job.AddPatch(patchMethod);
}
foreach (var job in jobs.GetJobs())
{
lastOriginal = job.original;
if (unpatch)
ProcessUnpatchJob(job);
else
ProcessPatchJob(job);
}
return jobs.GetReplacements();
}
void ProcessPatchJob(PatchJobs<MethodInfo>.Job job)
{
MethodInfo replacement = default;
View on GitHub (pinned to e7872dc170)