{"record":{"id":"bec0ea03af64f1ec","repo":"bchavez/Bogus","slug":"can-t-parse-methodname-because-the-dataset-was-n","errorCode":null,"errorMessage":"Can't parse {methodName} because the dataset was not provided in the {nameof(dataSets)} parameter.","messagePattern":"Can't parse (.+?) because the dataset was not provided in the (.+?) parameter\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Tokenizer.cs","lineNumber":98,"sourceCode":"      var fakeVal = mm.Method.Invoke(dataSet, argumentList).ToString();\n\n      var sb = new StringBuilder();\n      sb.Append(str, 0, start);\n      sb.Append(fakeVal);\n      sb.Append(str.Substring(end + 2));\n\n      return Parse(sb.ToString(), dataSets);\n   }\n\n   private static object FindDataSetWithMethod(object[] dataSets, string methodName)\n   {\n      var dataSetType = MustashMethods[methodName].First().Method.DeclaringType;\n\n      var ds = dataSets.FirstOrDefault(o => o.GetType() == dataSetType);\n\n      if( ds == null )\n      {\n         throw new ArgumentException($\"Can't parse {methodName} because the dataset was not provided in the {nameof(dataSets)} parameter.\", nameof(dataSets));\n      }\n      return ds;\n   }\n\n   private static void ParseMustashText(string str, int start, int end, out string methodName, out string[] arguments)\n   {\n      var methodCall = str.Substring(start + 2, end - start - 2)\n         .Replace(\"}}\", \"\")\n         .Replace(\"{{\", \"\");\n\n      var argumentsStart = methodCall.IndexOf(\"(\", StringComparison.Ordinal);\n      if (argumentsStart != -1)\n      {\n         var argumentsString = GetArgumentsString(methodCall, argumentsStart);\n         methodName = methodCall.Substring(0, argumentsStart).Trim();\n         arguments = argumentsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();\n      }\n      else","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Tokenizer.cs#L80-L116","documentation":"Thrown by Tokenizer.FindDataSetWithMethod (Tokenizer.cs:98) while resolving a {{category.method}} handlebar. The method name was found in the static MustashMethods registry (built once from Faker's [RegisterMustasheMethods] properties), so the category is known, but none of the object instances passed in the dataSets params array has the EXACT declaring type that owns that method. The library throws because reflection invocation needs a target instance and there is no matching one.","triggerScenarios":"Calling the low-level Tokenizer.Parse(template, dataSets...) directly and omitting the dataset the template references, e.g. Tokenizer.Parse(\"{{internet.email}}\", faker.Name) passes Name but not Internet, so no object has GetType()==typeof(Internet). Note the match is exact (o.GetType()==dataSetType), so a subclass/wrapper/proxy of a dataset also fails. The public Faker.Parse(string) does NOT trigger this because Faker.cs:81-97 forwards all 15 datasets.","commonSituations":"Migrating from Faker.Parse to Tokenizer.Parse to inject a custom/seeded dataset subset and forgetting one; sharing one template string across code paths that pass different dataset subsets; passing a mocked or subclassed dataset whose runtime type differs from the registered declaring type; using Random/Date from a different Faker instance than expected.","solutions":["Prefer Faker.Parse(string) (or Faker<T>.Parse), which forwards every registered dataset, instead of hand-picking a list for Tokenizer.Parse.","If you must call Tokenizer.Parse directly, pass every dataset the template may touch; the error message names the offending {methodName} whose category instance is missing.","Make sure each passed instance's runtime type exactly equals the registered declaring type (no subclasses/wrappers). If you subclassed a dataset, register that subclass type via Tokenizer.RegisterMustashMethods and pass the subclass instance."],"exampleFix":"// before\nvar s = Tokenizer.Parse(\"{{internet.email}} ({{name.firstname}})\", faker.Name);\n// after\nvar s = Tokenizer.Parse(\"{{internet.email}} ({{name.firstname}})\", faker.Internet, faker.Name);\n// or simply\nvar s = faker.Parse(\"{{internet.email}} ({{name.firstname}})\");","handlingStrategy":"validation","validationCode":"// Before calling Tokenizer.Parse directly, confirm every {{cat.method}} in the template\n// has its declaring-type instance present in the dataSets you pass.\nstatic void AssertDatasetsProvided(string template, params object[] dataSets)\n{\n    var present = new HashSet<Type>(dataSets.Select(o => o.GetType()));\n    foreach (Match m in Regex.Matches(template, @\"\\{\\{\\s*([^.}\\s]+)\\.\"))\n    {\n        var category = m.Groups[1].Value.ToUpperInvariant();\n        if (!Tokenizer.MustashMethods.Contains(category)) continue; // different error\n        var declType = Tokenizer.MustashMethods[category].First().Method.DeclaringType;\n        if (!present.Contains(declType))\n            throw new InvalidOperationException($\"Template needs dataset {declType.Name} (category '{category.ToLower()}') which was not passed.\");\n    }\n}","typeGuard":"// Narrow each passed object to its exact registered type (the matcher uses ==, not IsAssignableFrom).\nstatic bool IsRegisteredDataset<TExpected>(object ds) => ds != null && ds.GetType() == typeof(TExpected);","tryCatchPattern":"try { var s = Tokenizer.Parse(tpl, datasets); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(dataSets) || ex.Message.Contains(\"dataset was not provided\"))\n{\n    // ex.ParamName is \"dataSets\" for this specific throw.\n    throw new InvalidOperationException($\"Template references a dataset not supplied: {tpl}\", ex);\n}","preventionTips":["Default to Faker.Parse(string); only drop to Tokenizer.Parse when you have a concrete reason.","If you pass a custom dataset subset, pass the FULL set unless you are certain of the template's needs.","Never wrap a dataset in a subclass/proxy and expect the matcher to accept it; it matches the exact type."],"tags":["mustache-template","dataset","tokenizer","bogus"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}