{"record":{"id":"ff1410fa7c510915","repo":"bchavez/Bogus","slug":"unknown-method-methodname-can-t-be-found","errorCode":null,"errorMessage":"Unknown method {methodName} can't be found.","messagePattern":"Unknown method (.+?) can't be found\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Tokenizer.cs","lineNumber":64,"sourceCode":"   }\n\n   public static string Parse(string str, params object[] dataSets)\n   {\n      //Recursive base case. If there are no more {{ }} handle bars,\n      //return.\n      var start = str.IndexOf(\"{{\", StringComparison.Ordinal);\n      var end = str.IndexOf(\"}}\", StringComparison.Ordinal);\n      if( start == -1 && end == -1 )\n      {\n         return str;\n      }\n\n      //We have some handlebars to process. Get the method name and arguments.\n      ParseMustashText(str, start, end, out var methodName, out var arguments);\n\n      if( !MustashMethods.Contains(methodName) )\n      {\n         throw new ArgumentException($\"Unknown method {methodName} can't be found.\");\n      }\n\n      //At this point, we have a methodName like: RANDOMIZER.NUMBER\n      //and if the dataset was registered with RegisterMustasheMethodsAttribute\n      //we should be able to extract the dataset given it's methodName.\n      var dataSet = FindDataSetWithMethod(dataSets, methodName);\n\n      //Considering arguments, lets get the best method overload\n      //that maps to a registered MustashMethod.\n      var mm = FindMustashMethod(methodName, arguments);\n      var providedArgumentList = ConvertStringArgumentsToObjects(arguments, mm);\n      var optionalArgs = mm.OptionalArgs.Take(mm.Method.GetParameters().Length - providedArgumentList.Length);\n      var argumentList = providedArgumentList.Concat(optionalArgs).ToArray();\n\n      //make the actual invocation.\n      var fakeVal = mm.Method.Invoke(dataSet, argumentList).ToString();\n\n      var sb = new StringBuilder();","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Tokenizer.cs#L46-L82","documentation":"Thrown by Tokenizer.Parse when a handlebars token '{{method}}' in the input string does not match any registered MustashMethod name. Method names are uppercased and namespaced like 'RANDOMIZER.NUMBER'; only methods on datasets marked with RegisterMustasheMethodsAttribute are registered.","triggerScenarios":"Calling 'Hello {{name.fullname}}'.ParseWith(faker) where 'NAME.FULLNAME' is not a registered method (correct is 'NAME.FULLNAME' only if registered; typo or unknown dataset method triggers it).","commonSituations":"Typos in template tokens, using a method that is not exposed on a registered dataset, or calling Tokenizer.Parse without registering custom mustash methods.","solutions":["Use only registered method names (e.g. {{name.firstname}}, {{randomizer.number}}) - check available MustashMethods.","Register custom dataset methods via RegisterMustasheMethodsAttribute and Tokenizer.RegisterMustashMethods.","Verify the exact uppercased method name with Tokenizer.MustashMethods lookup before templating."],"exampleFix":"// before\nvar s = \"{{name.fullname}}\".Parse(f.Name, f.Random);\n// after (use registered method)\nvar s = \"{{name.fullname}}\".Parse(f); // ensure NAME.FULLNAME is registered; else {{name.firstname}}","handlingStrategy":"validation","validationCode":"static string SafeParse(string template, params object[] datasets) {\n    foreach (var m in System.Text.RegularExpressions.Regex.Matches(template, @\"\\{\\{(.*?)\\}\"))\n        if (!Tokenizer.MustashMethods.Contains(m.ToString().Trim('{}').ToUpperInvariant()))\n            throw new InvalidOperationException($\"unknown mustash method: {m}\");\n    return Tokenizer.Parse(template, datasets);\n}","typeGuard":"bool AllTokensRegistered(string template) =>\n    System.Text.RegularExpressions.Regex.Matches(template, @\"\\{\\{(.*?)\\}\")\n        .Cast<System.Text.RegularExpressions.Match>()\n        .All(m => Tokenizer.MustashMethods.Contains(m.Groups[1].Value.ToUpperInvariant()));","tryCatchPattern":"try { return Tokenizer.Parse(template, datasets); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Unknown method\")) {\n    // strip or correct the unknown token and retry\n}","preventionTips":["Restrict templates to registered mustash method names.","Register custom dataset methods with RegisterMustasheMethodsAttribute.","Lint template tokens against Tokenizer.MustashMethods in tests."],"tags":["bogus","tokenizer","mustash","handlebars","unknown-method"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}