bchavez/Bogus · error · BogusException
The locale '{locale}' does not exist. To see all available l
Error message
The locale '{locale}' does not exist. To see all available locales visit {AssemblyVersionInformation.AssemblyDescription}. What it means
Thrown by the DataSet constructor when Database.LocaleResourceExists(locale) returns false, i.e. the supplied locale string does not match any locale JSON resource embedded in the Bogus assembly. The message appends AssemblyVersionInformation.AssemblyDescription to point at the project/GitHub URL where the locale list lives. Bogus uses underscore-delimited locale codes (e.g. "en_US"), not .NET hyphenated culture names ("en-US").
Source
Thrown at Source/Bogus/DataSet.cs:24
namespace Bogus;
/// <summary>
/// Data set methods that access the BSON database of locales.
/// </summary>
public class DataSet : ILocaleAware, IHasRandomizer
{
/// <summary>
/// Initializes a new instance of the <see cref="DataSet"/> class.
/// </summary>
/// <param name="locale">The locale wanting to be set. Default is "en" for English.</param>
/// <exception cref="BogusException">
/// When the given <paramref name="locale"/> isn't found.
/// </exception>
public DataSet(string locale = "en")
{
if (!Database.LocaleResourceExists(locale))
{
throw new BogusException(
$"The locale '{locale}' does not exist. To see all available locales visit {AssemblyVersionInformation.AssemblyDescription}.");
}
this.Locale = locale;
this.Category = ResolveCategory(this.GetType());
}
/// <summary>
/// Gets or sets the category name inside the locale.
/// </summary>
protected string Category { get; set; }
/// <summary>
/// Gets or sets the current locale of the data set.
/// </summary>
public string Locale { get; set; }
View on GitHub (pinned to 6ece18c5c2)
Solutions
- Replace the hyphenated culture name with the Bogus underscore locale code, e.g. "en_US" instead of "en-US".
- Call Bogus.Database.GetAllLocales() to print the exact set of supported locale codes and copy one verbatim.
- Fall back to the default "en" locale while you confirm the exact code you need.
Example fix
// before
var f = new Faker<MyObj>("en-US");
// after
var f = new Faker<MyObj>("en_US"); Defensive patterns
Strategy: validation
Validate before calling
using Bogus;
string locale = "en_US";
if (!Database.LocaleResourceExists(locale))
{
var valid = string.Join(", ", Database.GetAllLocales());
throw new ArgumentException($"Locale '{locale}' is not bundled. Valid: {valid}");
}
var faker = new Faker<MyObj>(locale); Prevention
- Use the underscore locale form (en_US), never the hyphen culture form (en-US).
- Call Database.GetAllLocales() once at startup and log the set your Bogus version supports.
- Treat locale as a known constant, not free user input.
When it happens
Trigger: Calling new DataSet("de-DE"), new Faker<T>("en-US"), new Person("xy_ZZ") or any API that takes a locale string with a code that is not one of the bundled locales. Also triggered by typos, wrong casing, or passing a full culture name where a Bogus locale code is expected.
Common situations: Copying a .NET CultureInfo.Name (hyphen form like "en-US", "pt-BR") straight into a Faker constructor. Using a locale Bogus does not bundle. Upgrading Bogus and assuming a locale that was never shipped exists.
Related errors
- Invalid country code
- The country code must be an ISO3166 two-letter country code.
- Gender not handled.
- The specified property '{property.Name}' does not have a set
- {nameof(amountToPick)} needs to be a positive integer.
AI-assisted analysis of bchavez/Bogus@6ece18c5c2 (2026-08-13).
Data as JSON: /api/errors/6870883cc90c37a2.
Report an issue: GitHub.