pardeike/Harmony · error · ArgumentException
[ ]
Error message
{note} [{info.methodName}] What it means
When Harmony performs a bulk patch (HarmonyPatchAll / TargetMethods style), target selection is done collectively, so individual patch methods must not also specify a target by name. A patch method carrying methodName alongside TargetMethod/TargetMethods/[HarmonyPatchAll] is ambiguous and is rejected.
Solutions
- Remove the methodName from the patch method's HarmonyPatch/HarmonyMethod attribute and let TargetMethod/TargetMethods decide the target
- Or remove TargetMethod/TargetMethods/[HarmonyPatchAll] from the class if you want per-method targeting
- Keep target selection in exactly one place per patch class
Example fix
// before
[HarmonyPatch("Update")]
static void Postfix() { }
// class also has: static MethodBase TargetMethod() => ...
// after
static void Postfix() { } // target comes from TargetMethod()/TargetMethods() Defensive patterns
Strategy: validation
Validate before calling
var hasBulk = type.GetMethod("TargetMethod") != null || type.GetMethod("TargetMethods") != null || hasHarmonyPatchAll;
var bad = patchMethods.Where(p => p.info.methodName != null); Prevention
- Pick one targeting style per patch class: either attributes or TargetMethod/TargetMethods
- Review patch classes after refactoring between bulk and per-method styles
When it happens
Trigger: BulkPatch processing a patch method whose HarmonyMethod/HarmonyPatch info has a non-null methodName while the class also uses TargetMethod, TargetMethods, or [HarmonyPatchAll].
Common situations: Adding [HarmonyPatch("SomeMethod")] to a patch class that already defines a static TargetMethod(); copy-pasting annotated patch methods into an [HarmonyPatchAll] class; refactoring a class from individual annotations to bulk patching without cleaning attributes.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- [ ]
- [ ]
- cannot contain zeros
- Cannot directly reference dynamic method \
- Using requires an additional attribute for specifying the…
AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15).
Data as JSON: /api/errors/e5bbbda3315d77a0.
Report an issue: GitHub.
Appendix: source
Thrown at Harmony/Public/PatchClassProcessor.cs:148
lock (PatchProcessor.locker)
_ = reversePatcher.Patch();
}
}
}
List<MethodInfo> BulkPatch(List<MethodBase> originals, ref MethodBase lastOriginal, bool unpatch)
{
var jobs = new PatchJobs<MethodInfo>();
for (var i = 0; i < originals.Count; i++)
{
lastOriginal = originals[i];
var job = jobs.GetJob(lastOriginal);
foreach (var patchMethod in patchMethods)
{
var note = "You cannot combine TargetMethod, TargetMethods or [HarmonyPatchAll] with individual annotations";
var info = patchMethod.info;
if (info.methodName is not null)
throw new ArgumentException($"{note} [{info.methodName}]");
if (info.methodType.HasValue && info.methodType.Value != MethodType.Normal)
throw new ArgumentException($"{note} [{info.methodType}]");
if (info.argumentTypes is not null)
throw new ArgumentException($"{note} [{info.argumentTypes.Description()}]");
job.AddPatch(patchMethod);
}
}
foreach (var job in jobs.GetJobs())
{
lastOriginal = job.original;
if (unpatch)
ProcessUnpatchJob(job);
else
ProcessPatchJob(job);
}
return jobs.GetReplacements();
}
View on GitHub (pinned to e7872dc170)