{"record":{"id":"8be796a8247f16a0","repo":"pardeike/Harmony","slug":"cannot-not-find-method-for-type-methodtype-and-name","errorCode":null,"errorMessage":"Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}","messagePattern":"Cannot not find method for type (.+?) and name (.+?) and parameters (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Public/HarmonyMethod.cs","lineNumber":134,"sourceCode":"\t\t/// <param name=\"priority\">The patch <see cref=\"Priority\"/></param>\r\n\t\t/// <param name=\"before\">A list of harmony IDs that should come after this patch</param>\r\n\t\t/// <param name=\"after\">A list of harmony IDs that should come before this patch</param>\r\n\t\t/// <param name=\"debug\">Set to true to generate debug output</param>\r\n\t\t///\r\n\t\tpublic HarmonyMethod(Delegate @delegate, int priority = -1, string[] before = null, string[] after = null, bool? debug = null)\r\n\t\t\t: this(@delegate.Method, priority, before, after, debug)\r\n\t\t{ }\r\n\r\n\t\t/// <summary>Creates a patch from a given method</summary>\r\n\t\t/// <param name=\"methodType\">The patch class/type</param>\r\n\t\t/// <param name=\"methodName\">The patch method name</param>\r\n\t\t/// <param name=\"argumentTypes\">The optional argument types of the patch method (for overloaded methods)</param>\r\n\t\t///\r\n\t\tpublic HarmonyMethod(Type methodType, string methodName, Type[] argumentTypes = null)\r\n\t\t{\r\n\t\t\tvar result = AccessTools.Method(methodType, methodName, argumentTypes);\r\n\t\t\tif (result is null)\r\n\t\t\t\tthrow new ArgumentException($\"Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}\");\r\n\t\t\tImportMethod(result);\r\n\t\t}\r\n\r\n\t\t/// <summary>Gets the names of all internal patch info fields</summary>\r\n\t\t/// <returns>A list of field names</returns>\r\n\t\t///\r\n\t\tpublic static List<string> HarmonyFields()\r\n\t\t{\r\n\t\t\treturn [.. AccessTools\r\n\t\t\t\t.GetFieldNames(typeof(HarmonyMethod))\r\n\t\t\t\t.Where(s => s != \"method\")];\r\n\t\t}\r\n\r\n\t\t/// <summary>Merges annotations</summary>\r\n\t\t/// <param name=\"attributes\">The list of <see cref=\"HarmonyMethod\"/> to merge</param>\r\n\t\t/// <returns>The merged <see cref=\"HarmonyMethod\"/></returns>\r\n\t\t///\r\n\t\tpublic static HarmonyMethod Merge(List<HarmonyMethod> attributes)\r","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/HarmonyMethod.cs#L116-L152","documentation":"This HarmonyMethod constructor builds a patch descriptor from a type + method name (+ optional argument types). It resolves via AccessTools.Method and throws ArgumentException when no matching method exists, so the descriptor can never be created.","triggerScenarios":"new HarmonyMethod(typeof(T), \"MethodName\") where MethodName is missing/renamed, or the parameters array filters out every overload; also when the method is defined on a base type not matched by the resolver.","commonSituations":"Target library refactor renamed or removed the patched method; attribute-style patches converted to manual HarmonyMethod instances after an update; typos and case mismatches in the method name.","solutions":["Correct the method name and verify with AccessTools.Method(methodType, methodName, argumentTypes)","Provide exact argumentTypes to match the intended overload","Construct the HarmonyMethod from a MethodInfo (new HarmonyMethod(mi)) obtained with your own null-checked lookup","Version-check the target assembly at startup and disable/log when the method signature changed"],"exampleFix":"// before\nvar patch = new HarmonyMethod(typeof(Game), \"ApllyDamage\");\n// after\nvar mi = AccessTools.Method(typeof(Game), nameof(Game.ApplyDamage));\nif (mi is null) throw new InvalidOperationException(\"Game.ApplyDamage missing\");\nvar patch = new HarmonyMethod(mi);","handlingStrategy":"validation","validationCode":"var mi = AccessTools.Method(methodType, methodName, argumentTypes);\nif (mi is null) throw new InvalidOperationException($\"Patch target {methodType}.{methodName} not found\");\nvar patch = new HarmonyMethod(mi);","typeGuard":"bool IsPatchable(Type t, string n) => AccessTools.Method(t, n) is not null;","tryCatchPattern":"try { patch = new HarmonyMethod(methodType, methodName, argumentTypes); } catch (ArgumentException ex) { log.Error($\"Patch target missing: {methodType}.{methodName}\", ex); throw; }","preventionTips":["Use nameof() for method names","Provide argumentTypes for overloads","Verify target method presence at startup and degrade gracefully when signatures change"],"tags":["patching","reflection","method-resolution","csharp"],"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"}