AvaloniaUI/Avalonia · error · FormatException
Bad format specifier.
Error message
Bad format specifier.
What it means
Thrown by ThrowFormatException_BadFormatSpecifier() in the Pooled collections ThrowHelper. This is a reserved/internal throw helper for malformed format specifiers during string formatting inside the pooled-array utilities. In the current Avalonia codebase this helper has no call sites — it is vestigial dead code ported from .NET's internal collections, so it is effectively unreachable through any public API.
Source
Thrown at src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs:336
throw new InvalidOperationException("No value provided.");
}
[DoesNotReturn]
internal static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported()
{
throw new InvalidOperationException("Concurrent operations are not supported.");
}
[DoesNotReturn]
internal static void ThrowInvalidOperationException_HandleIsNotInitialized()
{
throw new InvalidOperationException("Handle is not initialized.");
}
[DoesNotReturn]
internal static void ThrowFormatException_BadFormatSpecifier()
{
throw new FormatException("Bad format specifier.");
}
private static ArgumentException GetArgumentException(ExceptionResource resource)
{
return new ArgumentException(GetResourceString(resource));
}
private static InvalidOperationException GetInvalidOperationException(ExceptionResource resource)
{
return new InvalidOperationException(GetResourceString(resource));
}
private static ArgumentException GetWrongKeyTypeArgumentException(object? key, Type targetType)
{
return new ArgumentException($"Wrong key type. Expected {targetType}, got: '{key}'.", nameof(key));
}
private static ArgumentException GetWrongValueTypeArgumentException(object? value, Type targetType)View on GitHub (pinned to 11c5427268)
Solutions
- Confirm the exception originates from Avalonia.Base Pooled code and not your own FormatException; check the full stack trace for the actual caller.
- If it appears in a fork, audit any new format-parsing code that calls ThrowFormatException_BadFormatSpecifier and validate the specifier before calling.
- In a stock build this should never fire — file an issue against Avalonia if it does, including the stack trace.
Defensive patterns
Strategy: try-catch
Validate before calling
// No public caller exists; if you maintain a fork that wires this helper, // validate the format specifier before delegating to it. if (!IsValidSpecifier(token)) return;
Try / catch
try { /* format-parsing path in forked pooled code */ }
catch (FormatException ex) when (ex.Message == "Bad format specifier.")
{
// log and fall back to default formatting
} Prevention
- In stock Avalonia this is unreachable — treat any sighting as a signal of a custom/forked build and audit new format-parsing code.
- Keep ThrowHelper throw helpers wired only behind validated parsing entry points.
When it happens
Trigger: Only reachable if a future change wires ThrowFormatException_BadFormatSpecifier() into a format-parsing path in the Pooled collections. Today there is no caller; searching the entire repo returns only the definition at ThrowHelper.cs:334.
Common situations: You will not encounter this in normal Avalonia development. If you do see it, a custom fork or unreleased build added a format-string parser that delegates to this helper and was passed an invalid specifier token.
Related errors
- Not supported format
- Invalid CornerRadius.
- Invalid BindingValueType.
- Unknown binding path element type {element.GetType().FullNam
- Unknown format specifier
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/588c5cfb2ba138e4.
Report an issue: GitHub.