{"record":{"id":"089fa2ba304a1c84","repo":"microsoft/aspire","slug":"invalid-boolean-value-value-expected-true-or-false","errorCode":null,"errorMessage":"Invalid boolean value: '{value}'. Expected 'true' or 'false'.","messagePattern":"Invalid boolean value: '(.+?)'\\. Expected 'true' or 'false'\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Configuration/FlexibleBooleanConverter.cs","lineNumber":35,"sourceCode":"    public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        return reader.TokenType switch\n        {\n            JsonTokenType.True => true,\n            JsonTokenType.False => false,\n            JsonTokenType.String => ParseString(reader.GetString()),\n            _ => throw new JsonException($\"Unexpected token parsing boolean. Token: {reader.TokenType}\")\n        };\n    }\n\n    private static bool ParseString(string? value)\n    {\n        if (bool.TryParse(value, out var result))\n        {\n            return result;\n        }\n\n        throw new JsonException($\"Invalid boolean value: '{value}'. Expected 'true' or 'false'.\");\n    }\n\n    public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)\n    {\n        writer.WriteBooleanValue(value);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":43,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Configuration/FlexibleBooleanConverter.cs#L17-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n\"features\": { \"experimentalFeature\": \"yes\" }\n// after\n\"features\": { \"experimentalFeature\": \"true\" }","handlingStrategy":"validation","validationCode":"var trimmed = raw?.Trim();\nif (!bool.TryParse(trimmed, out _))\n    throw new FormatException($\"Value '{raw}' must be 'true' or 'false'.\");","typeGuard":"static bool IsValidBooleanString(string? s) => bool.TryParse(s, out _);","tryCatchPattern":"try\n{\n    var value = JsonSerializer.Deserialize<MyConfig>(json, options);\n}\ncatch (JsonException ex) when (ex.Message.Contains(\"Invalid boolean value\"))\n{\n    logger.LogError(ex, \"Config contains a non-boolean string where true/false expected.\");\n}","preventionTips":["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."],"tags":["json","configuration","deserialization"],"backgroundTag":"invalid-config-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}