{"record":{"id":"3092c5673d08dfad","repo":"microsoft/aspire","slug":"cannot-convert-reader-tokentype-to-boolean-for-key-key","errorCode":null,"errorMessage":"Cannot convert {reader.TokenType} to boolean for key '{key}'","messagePattern":"Cannot convert (.+?) to boolean for key '(.+?)'","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Configuration/FlexibleBooleanDictionaryConverter.cs","lineNumber":51,"sourceCode":"            {\n                return dictionary;\n            }\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n            {\n                throw new JsonException($\"Expected PropertyName, got {reader.TokenType}\");\n            }\n\n            var key = reader.GetString() ?? throw new JsonException(\"Property name cannot be null\");\n\n            reader.Read();\n\n            bool value = reader.TokenType switch\n            {\n                JsonTokenType.True => true,\n                JsonTokenType.False => false,\n                JsonTokenType.String => ParseBooleanString(reader.GetString(), key),\n                _ => throw new JsonException($\"Cannot convert {reader.TokenType} to boolean for key '{key}'\")\n            };\n\n            dictionary[key] = value;\n        }\n\n        throw new JsonException(\"Unexpected end of JSON\");\n    }\n\n    public override void Write(Utf8JsonWriter writer, Dictionary<string, bool> value, JsonSerializerOptions options)\n    {\n        writer.WriteStartObject();\n\n        foreach (var kvp in value)\n        {\n            writer.WriteBoolean(kvp.Key, kvp.Value);\n        }\n\n        writer.WriteEndObject();","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Configuration/FlexibleBooleanDictionaryConverter.cs#L33-L69","documentation":"Inside the dictionary converter, each property value must be a JSON true/false literal or a 'true'/'false' string; any other token (number, null, object, array) throws JsonException naming the token and key. The converter deliberately only flexes for string booleans.","triggerScenarios":"A value in a Dictionary<string,bool> config object that is a number (1/0), null, nested object, or array, e.g. \"featureFlags\": { \"MyFeature\": 1 }.","commonSituations":"Users familiar with other config systems writing 1/0 or yes/no; values interpolated from env vars carrying raw numbers; schema assumptions from other tooling.","solutions":["Replace the numeric/null value with true or false (or the strings \"true\"/\"false\") for the key named in the message.","If the value legitimately needs to be non-boolean, move it to a different config key, not the boolean dictionary.","If 1/0 support is desired, extend the switch's ParseBooleanString path to accept numeric tokens."],"exampleFix":"// before\n\"featureFlags\": { \"MyFeature\": 1 }\n// after\n\"featureFlags\": { \"MyFeature\": true }","handlingStrategy":"validation","validationCode":"using var doc = JsonDocument.Parse(json);\nforeach (var p in doc.RootElement.GetProperty(\"featureFlags\").EnumerateObject())\n{\n    if (p.Value.ValueKind is not (JsonValueKind.True or JsonValueKind.False or JsonValueKind.String))\n        throw new FormatException($\"Feature flag '{p.Name}' must be true/false or \\\"true\\\"/\\\"false\\\".\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var config = JsonSerializer.Deserialize<MyConfig>(json, options);\n}\ncatch (JsonException ex) when (ex.Message.Contains(\"Cannot convert\") && ex.Message.Contains(\"to boolean\"))\n{\n    logger.LogError(ex, \"Config dictionary contains a value that is not a boolean.\");\n}","preventionTips":["Use true/false (or \"true\"/\"false\") only — never 1/0 or null for boolean flags.","Coerce numeric boolean values at ingestion points (env var readers, scripts).","Document the expected config schema for team members."],"tags":["json","configuration","type-mismatch"],"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"}