{"record":{"id":"d721767f30a42673","repo":"bchavez/Bogus","slug":"cannot-find-a-method-methodname-that-could-acc","errorCode":null,"errorMessage":"Cannot find a method '{methodName}' that could accept {arguments.Length} arguments","messagePattern":"Cannot find a method '(.+?)' that could accept (.+?) arguments","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Tokenizer.cs","lineNumber":135,"sourceCode":"      {\n         methodName = methodCall;\n         arguments = new string[0];\n      }\n\n      methodName = methodName.ToUpperInvariant();\n   }\n\n   private static MustashMethod FindMustashMethod(string methodName, string[] arguments)\n   {\n      var selection =\n         from mm in MustashMethods[methodName]\n         orderby mm.Method.GetParameters().Count(pi => pi.IsOptional) - arguments.Length\n         where mm.Method.GetParameters().Length >= arguments.Length\n         where mm.OptionalArgs.Length + arguments.Length >= mm.Method.GetParameters().Length\n         select mm;\n\n      var found = selection.FirstOrDefault();\n      return found ?? throw new ArgumentException($\"Cannot find a method '{methodName}' that could accept {arguments.Length} arguments\");\n   }\n\n   private static object[] ConvertStringArgumentsToObjects(string[] parameters, MustashMethod mm)\n   {\n      try\n      {\n         return mm.Method.GetParameters()\n                         .Zip(parameters, GetValueForParameter)\n                         .ToArray();\n      }\n      catch (OverflowException ex)\n      {\n         throw new ArgumentOutOfRangeException($\"One of the arguments for {mm.Name} is out of supported range. Argument list: {string.Join(\",\", parameters)}\", ex);\n      }\n      catch (Exception ex) when (ex is InvalidCastException or FormatException)\n      {\n         throw new ArgumentException($\"One of the arguments for {mm.Name} cannot be converted to target type. Argument list: {string.Join(\",\", parameters)}\", ex);\n      }","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Tokenizer.cs#L117-L153","documentation":"Thrown by Tokenizer.FindMustashMethod (Tokenizer.cs:135). After the method name is known, Bogus tries to pick an overload whose parameter count can accept the supplied arguments (constraints: Method params.Length >= arg count, and optional args + arg count >= params.Length). If no registered overload satisfies both constraints, no overload matches and it throws. The name was valid; only the argument COUNT is wrong.","triggerScenarios":"A {{category.method(a,b,c)}} whose comma-separated argument count matches no overload. Randomizer.Number exposes Number() and Number(int min,int max), so {{random.number(5)}} (1 arg) and {{random.number(1,2,3)}} (3 args) both fail; {{name.firstname(\"x\")}} fails because FirstName takes 0 args.","commonSituations":"Assuming a single-argument convenience overload exists when only the 0-arg and 2-arg forms do; copy-pasting a template from docs of a different Bogus version where overloads changed; trailing empty-string arguments (the splitter uses RemoveEmptyEntries, but a stray comma in the middle still counts).","solutions":["Match the argument count to a real overload: check the dataset method signature (e.g. Randomizer.Number has 0-arg and 2-arg forms only).","Drop extraneous args or add required ones so the count falls between the method's required-parameter count and its total-parameter count.","Remember trailing optional parameters may be omitted, but you can never EXCEED the method's total parameter count."],"exampleFix":"// before\nfaker.Parse(\"{{random.number(1,2,3)}}\");\n// after\nfaker.Parse(\"{{random.number(1,100)}}\");","handlingStrategy":"validation","validationCode":"// Check that the argument count you intend matches at least one registered overload.\nstatic bool ArgCountOk(string categoryMethod, int argCount)\n{\n    var key = categoryMethod.ToUpperInvariant();\n    if (!Tokenizer.MustashMethods.Contains(key)) return false;\n    return Tokenizer.MustashMethods[key].Any(mm =>\n        mm.Method.GetParameters().Length >= argCount &&\n        mm.OptionalArgs.Length + argCount >= mm.Method.GetParameters().Length);\n}","typeGuard":null,"tryCatchPattern":"try { var s = faker.Parse(tpl); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"that could accept\") && ex.Message.Contains(\"arguments\"))\n{\n    // Argument-count mismatch; re-render with the offending template for diagnostics.\n    throw new InvalidOperationException($\"Bad arg count in template: {tpl}\", ex);\n}","preventionTips":["Before templating, glance at the dataset method signature to learn its overload set.","Keep argument lists minimal; prefer omitting optional trailing args over guessing counts.","Treat a sudden arg-count failure after a Bogus version bump as a likely overload change."],"tags":["mustache-template","method-overload","argument-count","tokenizer"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}