bchavez/Bogus · error · NotImplementedException
[{registrationNumberType}] is not a supported [{nameof(VatRe
Error message
[{registrationNumberType}] is not a supported [{nameof(VatRegistrationNumberType)}]. What it means
Finance.VatRegistrationNumber switch handles Standard and BranchTrader but throws NotImplementedException for any other VatRegistrationNumberType. (GovernmentDepartment and HealthAuthority are handled in the actual source, so the reachable trigger is an enum value supplied via an invalid cast, e.g. (VatRegistrationNumberType)99.) The guard is defensive against undefined enum inputs.
Source
Thrown at Source/Bogus/Extensions/UnitedKingdom/ExtensionsForUnitedKingdom.cs:120
? $"GB HA {random:000}"
: $"GBHA{random:000}";
case VatRegistrationNumberType.GovernmentDepartment:
return includeSeparator
? $"GB GD {random:000}"
: $"GBGD{random:000}";
case VatRegistrationNumberType.Standard:
int checksum = CalculateChecksum(random);
return includeSeparator
? $"GB {random:000 0000} {checksum:00}"
: $"GB{random:0000000}{checksum:00}";
case VatRegistrationNumberType.BranchTrader:
checksum = CalculateChecksum(random);
string suffix = finance.Random.ReplaceNumbers("###");
return includeSeparator
? $"GB {random:000 0000} {checksum:00} {suffix}"
: $"GB{random:0000000}{checksum:00}{suffix}";
default:
throw new NotImplementedException($"[{registrationNumberType}] is not a supported [{nameof(VatRegistrationNumberType)}].");
}
}
private static int CalculateChecksum(int n)
{
int total = 0;
int divisor = 1;
while( n / divisor >= 10 )
{
divisor *= 10;
}
int index = 0;
while( divisor > 0 )
{
int digit = n / divisor;
total += digit * (8 - index);View on GitHub (pinned to 6ece18c5c2)
Solutions
- Use one of the defined enum values: Standard, BranchTrader, GovernmentDepartment, HealthAuthority.
- If the value comes from an int, validate Enum.IsDefined(typeof(VatRegistrationNumberType), value) first.
- Treat NotImplementedException as a signal that an unsupported/invalid enum was passed and surface a clearer error to the caller.
Example fix
// before
var vat = finance.VatRegistrationNumber((VatRegistrationNumberType)typeId);
// after
if (!Enum.IsDefined(typeof(VatRegistrationNumberType), typeId))
throw new ArgumentException("Unknown VAT registration type");
var vat = finance.VatRegistrationNumber((VatRegistrationNumberType)typeId); Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(VatRegistrationNumberType), registrationNumberType))
throw new ArgumentOutOfRangeException(nameof(registrationNumberType));
var vat = finance.VatRegistrationNumber(registrationNumberType); Type guard
static bool IsKnownVatType(VatRegistrationNumberType t) => Enum.IsDefined(typeof(VatRegistrationNumberType), t);
Try / catch
try { return finance.VatRegistrationNumber(type); }
catch (NotImplementedException) { throw new ArgumentException($"Unsupported VAT type {type}"); } Prevention
- Use the four defined enum values only.
- Validate Enum.IsDefined when the value comes from an int.
- Treat NotImplementedException here as an invalid-enum signal and rethrow a clearer error.
When it happens
Trigger: Calling finance.VatRegistrationNumber((VatRegistrationNumberType)99) or any int cast to the enum that is not 0-3. With valid named enum values the guard is not reached.
Common situations: Deserializing a numeric type code into VatRegistrationNumberType without bounds checking, or an enum-extension scenario where a new member was added but not yet cased.
Related errors
- Invalid country code
- The country code must be an ISO3166 two-letter country code.
- The ISO3166 IBAN country code '{countryCode}' was not found.
- Gender not handled.
- Can only accept registration dates between {EarliestRegistra
AI-assisted analysis of bchavez/Bogus@6ece18c5c2 (2026-08-13).
Data as JSON: /api/errors/18f1c616c34ee9b1.
Report an issue: GitHub.