Humanizr/Humanizer · error · FormatException
EiB is outside the range supported by ByteSize.Bits.
Error message
EiB is outside the range supported by ByteSize.Bits.
What it means
Thrown by ByteSize.FindFormatUnit when the masked format contains the literal 'EiB'. The library cannot represent an exbibyte in its backed range (the supported ceiling is BytesInPebibyte*1024, one byte short of a full exbibyte of bits in a signed long), so the EiB token is rejected explicitly even though it belongs to the binary IEC family.
Source
Thrown at src/Humanizer/Bytes/ByteSize.cs:1034
{
if (string.IsNullOrWhiteSpace(format) || format == "G")
{
return null;
}
var maskedFormat = MaskFormatLiterals(format!);
var incompatibleUnits = ReferenceEquals(units, DecimalUnits) ? BinaryUnits : DecimalUnits;
foreach (var unit in incompatibleUnits)
{
if (maskedFormat.Contains(unit.Symbol, StringComparison.OrdinalIgnoreCase))
{
throw new FormatException($"Unit token '{unit.Symbol}' does not belong to the selected byte-size unit system.");
}
}
if (maskedFormat.Contains("EiB", StringComparison.OrdinalIgnoreCase))
{
throw new FormatException("EiB is outside the range supported by ByteSize.Bits.");
}
SystemUnit? selectedUnit = null;
var remainingFormat = maskedFormat;
foreach (var unit in units)
{
if (!remainingFormat.Contains(unit.Symbol, StringComparison.OrdinalIgnoreCase))
{
continue;
}
if (selectedUnit is not null && selectedUnit.Value.DataUnit != unit.DataUnit)
{
throw new FormatException("A byte-size format can contain only one distinct unit token.");
}
selectedUnit = unit;
remainingFormat = ReplaceOrdinalIgnoreCase(View on GitHub (pinned to ffc2b77c0f)
Solutions
- Drop the EiB token from the format string; the largest representable binary unit is PiB.
- For values near one EiB, format in PiB (which will show ~1024 PiB) or switch to a custom ulong-bits representation.
- Quote 'EiB' as a literal ('"EiB"') only if you want the letters as decoration, not as a unit token.
Example fix
// before
var text = size.ToString("#.## EiB");
// after
var text = size.ToString("#.## PiB"); // largest supported binary token Defensive patterns
Strategy: validation
Validate before calling
static string StripEib(string format) =>
format.Contains("EiB", StringComparison.OrdinalIgnoreCase)
? throw new ArgumentException("EiB is not supported; use PiB.")
: format; Try / catch
try { return size.ToString(format); }
catch (FormatException) { throw new ArgumentException("EiB token is not supported by ByteSize.", nameof(format)); } Prevention
- The largest supported binary token is PiB
- Do not auto-generate IEC format strings from a full unit list
- Quote 'EiB' if it must appear as decoration
When it happens
Trigger: Calling ToString("#.## EiB", ...) on a ByteSize, or passing an IEC format string that includes the exbibyte token. The check is case-insensitive and runs after the incompatible-system scan.
Common situations: Generating format strings programmatically from a list of IEC units without filtering out EiB, or copy-pasting a max-capacity format from documentation that assumes exbibyte support exists.
Related errors
- Unit token '{unit.Symbol}' does not belong to the selected b
- A byte-size format can contain only one distinct unit token.
- Unable to protect the byte-size unit token.
- Unknown byte-size unit system.
- Object is not a ByteSize
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/ccaf2694ba8814da.
Report an issue: GitHub.