{"record":{"id":"7235e13723151d24","repo":"tui-cs/Terminal.Gui","slug":"propertyname-both-foreground-and-background-col","errorCode":null,"errorMessage":"{propertyName}: Both Foreground and Background colors must be provided.","messagePattern":"(.+?): Both Foreground and Background colors must be provided\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/AttributeJsonConverter.cs","lineNumber":45,"sourceCode":"        if (reader.TokenType != JsonTokenType.StartObject)\n        {\n            throw new JsonException ($\"Unexpected StartObject token when parsing Attribute: {reader.TokenType}.\");\n        }\n\n        var attribute = new Attribute ();\n        Color? foreground = null;\n        Color? background = null;\n        TextStyle? style = null;\n\n        string propertyName = string.Empty;\n\n        while (reader.Read ())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n            {\n                if (foreground is null || background is null)\n                {\n                    throw new JsonException ($\"{propertyName}: Both Foreground and Background colors must be provided.\");\n                }\n\n                if (style.HasValue)\n                {\n                    return new Attribute (foreground.Value, background.Value, style.Value);\n                }\n                else\n                {\n                    return new Attribute (foreground.Value, background.Value);\n                }\n            }\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n            {\n                throw new JsonException ($\"{propertyName}: Unexpected token when parsing Attribute: {reader.TokenType}.\");\n            }\n\n            propertyName = reader.GetString ()!;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/AttributeJsonConverter.cs#L27-L63","documentation":"Thrown as JsonException by AttributeJsonConverter.Read at the EndObject token when either Foreground or Background is still null. An Attribute requires both a foreground and a background color; supplying only one is ambiguous. The message includes the last-read propertyName for context. Style is optional.","triggerScenarios":"Writing an Attribute object in config JSON with only a Foreground key and no Background (or vice versa); omitting a color field; a typo in the key name (e.g. \"Foregound\") so the parser treats it as an unknown property and never assigns the nullable.","commonSituations":"Hand-authoring theme JSON and forgetting the second color; copy-paste errors in large scheme definitions; key casing/typos that silently bypass the Foreground/Background cases.","solutions":["Provide both Foreground and Background in every Attribute object in config JSON.","Double-check key spelling and casing: 'Foreground' and 'Background' (the parser lowercases for comparison, but typos still miss).","Validate the config file with a schema or a quick parse test before applying it."],"exampleFix":"// before (config.json)\n\"Normal\": { \"Foreground\": \"red\" }\n\n// after\n\"Normal\": { \"Foreground\": \"red\", \"Background\": \"black\" }","handlingStrategy":"validation","validationCode":"// Validate config JSON before applying:\n// every Attribute object must contain both Foreground and Background.\nforeach (var attr in /* locate Attribute objects */)\n{\n    bool hasFg = attr.TryGetProperty (\"Foreground\", out _);\n    bool hasBg = attr.TryGetProperty (\"Background\", out _);\n    if (!hasFg || !hasBg)\n    {\n        throw new InvalidOperationException (\"Attribute requires both Foreground and Background.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configText);\n}\ncatch (JsonException ex)\n{\n    Logging.Error ($\"Incomplete Attribute in config: {ex.Message}\");\n}","preventionTips":["Always include both Foreground and Background in every Attribute object.","Check key spelling and casing (Foreground/Background).","Test-parse theme JSON before applying it in production."],"tags":["config","json","serialization","theme"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}