{"record":{"id":"f12a515547462372","repo":"pardeike/Harmony","slug":"undefined-target-method-for-patch-method-patchmethod-info","errorCode":null,"errorMessage":"Undefined target method for patch method {patchMethod.info.method.FullDescription()}","messagePattern":"Undefined target method for patch method (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Public/PatchClassProcessor.cs","lineNumber":175,"sourceCode":"\t\t\tforeach (var job in jobs.GetJobs())\r\n\t\t\t{\r\n\t\t\t\tlastOriginal = job.original;\r\n\t\t\t\tif (unpatch)\r\n\t\t\t\t\tProcessUnpatchJob(job);\r\n\t\t\t\telse\r\n\t\t\t\t\tProcessPatchJob(job);\r\n\t\t\t}\r\n\t\t\treturn jobs.GetReplacements();\r\n\t\t}\r\n\r\n\t\tList<MethodInfo> PatchWithAttributes(ref MethodBase lastOriginal, bool unpatch)\r\n\t\t{\r\n\t\t\tvar jobs = new PatchJobs<MethodInfo>();\r\n\t\t\tforeach (var patchMethod in patchMethods)\r\n\t\t\t{\r\n\t\t\t\tlastOriginal = patchMethod.info.GetOriginalMethod();\r\n\t\t\t\tif (lastOriginal is null)\r\n\t\t\t\t\tthrow new ArgumentException($\"Undefined target method for patch method {patchMethod.info.method.FullDescription()}\");\r\n\r\n\t\t\t\tvar job = jobs.GetJob(lastOriginal);\r\n\t\t\t\tjob.AddPatch(patchMethod);\r\n\t\t\t}\r\n\t\t\tforeach (var job in jobs.GetJobs())\r\n\t\t\t{\r\n\t\t\t\tlastOriginal = job.original;\r\n\t\t\t\tif (unpatch)\r\n\t\t\t\t\tProcessUnpatchJob(job);\r\n\t\t\t\telse\r\n\t\t\t\t\tProcessPatchJob(job);\r\n\t\t\t}\r\n\t\t\treturn jobs.GetReplacements();\r\n\t\t}\r\n\r\n\t\tvoid ProcessPatchJob(PatchJobs<MethodInfo>.Job job)\r\n\t\t{\r\n\t\t\tMethodInfo replacement = default;\r","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/PatchClassProcessor.cs#L157-L193","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\n[HarmonyPatch(typeof(Player), \"MoveTo\", typeof(Vector3))]\n// after\nstatic MethodBase TargetMethod() =>\n    AccessTools.Method(typeof(Player), \"MoveTo\", new[] { typeof(Vector3) })\n    ?? AccessTools.Method(typeof(Player), \"MoveTo\");","handlingStrategy":"validation","validationCode":"var target = patchMethod.info.GetOriginalMethod();\nif (target is null) throw new ArgumentException($\"{patchMethod.info.method} does not resolve to a target\");","typeGuard":null,"tryCatchPattern":"try { harmony.PatchAll(); } catch (ArgumentException e) when (e.Message.StartsWith(\"Undefined target method\")) { LogMissingTarget(e); }","preventionTips":["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"],"tags":["target-not-found","reflection","harmony","version-mismatch"],"backgroundTag":"resource-not-found","analyzedSha":"e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c","analyzedAt":"2026-09-15T22:47:11.550Z","contentChangedAt":"2026-09-15T22:47:11.550Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}