{"record":{"id":"7943e1f1f5c427c2","repo":"pardeike/Harmony","slug":"no-method-found-for-type-type-name-name-parameters","errorCode":null,"errorMessage":"No method found for type={type}, name={name}, parameters={parameters.Description()}, generics={generics.Description()}","messagePattern":"No method found for type=(.+?), name=(.+?), parameters=(.+?), generics=(.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Public/CodeInstruction.cs","lineNumber":115,"sourceCode":"\t\t{\r\n\t\t\tvar instruction = Clone();\r\n\t\t\tinstruction.operand = operand;\r\n\t\t\treturn instruction;\r\n\t\t}\r\n\r\n\t\t// --- CALLING\r\n\r\n\t\t/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>\r\n\t\t/// <param name=\"type\">The class/type where the method is declared</param>\r\n\t\t/// <param name=\"name\">The name of the method (case sensitive)</param>\r\n\t\t/// <param name=\"parameters\">Optional parameters to target a specific overload of the method</param>\r\n\t\t/// <param name=\"generics\">Optional list of types that define the generic version of the method</param>\r\n\t\t/// <returns>A code instruction that calls the method matching the arguments</returns>\r\n\t\t///\r\n\t\tpublic static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)\r\n\t\t{\r\n\t\t\tvar method = AccessTools.Method(type, name, parameters, generics);\r\n\t\t\tif (method is null) throw new ArgumentException($\"No method found for type={type}, name={name}, parameters={parameters.Description()}, generics={generics.Description()}\");\r\n\t\t\treturn new CodeInstruction(OpCodes.Call, method);\r\n\t\t}\r\n\r\n\t\t/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>\r\n\t\t/// <param name=\"typeColonMethodname\">The target method in the form <c>TypeFullName:MethodName</c>, where the type name matches a form recognized by <a href=\"https://docs.microsoft.com/en-us/dotnet/api/system.type.gettype\">Type.GetType</a> like <c>Some.Namespace.Type</c>.</param>\r\n\t\t/// <param name=\"parameters\">Optional parameters to target a specific overload of the method</param>\r\n\t\t/// <param name=\"generics\">Optional list of types that define the generic version of the method</param>\r\n\t\t/// <returns>A code instruction that calls the method matching the arguments</returns>\r\n\t\t///\r\n\t\tpublic static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)\r\n\t\t{\r\n\t\t\tvar method = AccessTools.Method(typeColonMethodname, parameters, generics);\r\n\t\t\tif (method is null) throw new ArgumentException($\"No method found for {typeColonMethodname}, parameters={parameters.Description()}, generics={generics.Description()}\");\r\n\t\t\treturn new CodeInstruction(OpCodes.Call, method);\r\n\t\t}\r\n\r\n\t\t/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>\r\n\t\t/// <param name=\"expression\">The lambda expression using the method</param>\r","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/CodeInstruction.cs#L97-L133","documentation":"CodeInstruction.Call(Type, string, ...) resolves the method via AccessTools.Method and emits a CALL instruction. If no method on the given type matches the name (and optional parameter/generic constraints), Harmony throws ArgumentException rather than emitting an invalid call.","triggerScenarios":"Calling CodeInstruction.Call(typeof(T), \"MethodName\") where MethodName does not exist, was renamed, is inherited-but-not-found by the resolver, or where the parameters/generics arrays filter out all overloads.","commonSituations":"Target library updated and renamed/removed the method; typo in method name; using method name only when a property getter (get_X) or overload set needs parameters specified; case-sensitivity mismatches.","solutions":["Verify the method exists on the type (AccessTools.Method(type, name) != null) and check spelling/case","Supply the exact parameters array to disambiguate overloads","Resolve the MethodInfo yourself first and use new CodeInstruction(OpCodes.Call, mi) so a clear null-check/log precedes the failure","Guard against target-version changes with an AccessTools.Method null check at patch startup"],"exampleFix":"// before\nvar call = CodeInstruction.Call(typeof(Logger), \"WriteMsg\");\n// after\nvar call = CodeInstruction.Call(typeof(Logger), nameof(Logger.WriteMessage), new[] { typeof(string) });","handlingStrategy":"validation","validationCode":"var mi = AccessTools.Method(type, name, parameters, generics);\nif (mi is null) throw new InvalidOperationException($\"Cannot emit call: {type}.{name} not found\");","typeGuard":"bool MethodExists(Type t, string n) => AccessTools.Method(t, n) is not null;","tryCatchPattern":"try { il.Append(CodeInstruction.Call(type, name, parameters)); } catch (ArgumentException ex) { log.Error($\"CodeInstruction.Call failed for {type?.Name}.{name}\", ex); throw; }","preventionTips":["Use nameof() and the Type-based overload instead of strings","Specify parameter types for overloaded methods","Null-check AccessTools.Method at patch init against all supported target versions"],"tags":["transpiler","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"}