microsoft/aspire · error · JsonException
Invalid boolean value
Error message
Invalid boolean value: '{value}'. Expected 'true' or 'false'. What it means
FlexibleBooleanConverter.Read parses a JSON string token as a bool via bool.TryParse; if the token cannot be parsed, the custom converter throws JsonException to fail deserialization of a flexible boolean setting. It exists so config values like "True"/"false" strings deserialize, but anything unparseable is rejected.
Solutions
- Open the JSON config file and replace the offending string with exactly 'true' or 'false' (quoted strings are accepted, casing-insensitively).
- If the value comes from an environment variable or script, fix the upstream source to emit 'true'/'false'.
- If you need looser parsing (yes/1/on), extend ParseString to accept those tokens before throwing.
Example fix
// before
"features": { "experimentalFeature": "yes" }
// after
"features": { "experimentalFeature": "true" } Defensive patterns
Strategy: validation
Validate before calling
var trimmed = raw?.Trim();
if (!bool.TryParse(trimmed, out _))
throw new FormatException($"Value '{raw}' must be 'true' or 'false'."); Type guard
static bool IsValidBooleanString(string? s) => bool.TryParse(s, out _);
Try / catch
try
{
var value = JsonSerializer.Deserialize<MyConfig>(json, options);
}
catch (JsonException ex) when (ex.Message.Contains("Invalid boolean value"))
{
logger.LogError(ex, "Config contains a non-boolean string where true/false expected.");
} Prevention
- Always write config boolean values as true/false (quoted strings are fine).
- Never store yes/1/on as boolean config values.
- Validate JSON config with a schema check before the CLI consumes it.
When it happens
Trigger: Deserializing configuration JSON where a property bound through this converter contains a string token other than (case-insensitive per TryParse) 'true'/'false'/'True'/'False' — e.g. "yes", "1", "on", or an empty string.
Common situations: Hand-edited aspire config files where the user wrote 'yes' or '1' instead of 'true'; config values interpolated from environment variables that contain unexpected text; older docs or other tools writing truthy strings.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Cannot convert string
- Expected StartObject, got
- Cannot convert to boolean for key
- Error deserializing GenAI message content. Error description
- Expected a non-empty Kubernetes MicroTime value.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/089fa2ba304a1c84.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/Configuration/FlexibleBooleanConverter.cs:35
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TokenType switch
{
JsonTokenType.True => true,
JsonTokenType.False => false,
JsonTokenType.String => ParseString(reader.GetString()),
_ => throw new JsonException($"Unexpected token parsing boolean. Token: {reader.TokenType}")
};
}
private static bool ParseString(string? value)
{
if (bool.TryParse(value, out var result))
{
return result;
}
throw new JsonException($"Invalid boolean value: '{value}'. Expected 'true' or 'false'.");
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteBooleanValue(value);
}
}
View on GitHub (pinned to 25830f84bd)