tui-cs/Terminal.Gui · error · JsonException

{propertyName}: Unknown Attribute property .

Error message

{propertyName}: Unknown Attribute property .

What it means

Thrown by the default case of AttributeJsonConverter.Read's switch: the JSON property name is not "foreground", "background", or "style" (compared case-insensitively). Attribute objects only accept those three keys. Note the trailing space + period in the message is a literal formatting quirk in the source.

Source

Thrown at Terminal.Gui/Configuration/AttributeJsonConverter.cs:99

                    case "style":
                        if (reader.TokenType != JsonTokenType.String)
                        {
                            throw new JsonException ($"{propertyName}: Expected a string value.");
                        }

                        try
                        {
                            style = Enum.Parse<TextStyle> (reader.GetString ()!, ignoreCase: true);
                        }
                        catch (ArgumentException ex)
                        {
                            throw new JsonException ("Expected a valid text style value.", ex);
                        }

                        break;

                    default:
                        throw new JsonException ($"{propertyName}: Unknown Attribute property .");
                }
            }
            catch (JsonException ex)
            {
                throw new JsonException ($"{propertyName}: \"{property}\" - {ex.Message}");
            }
        }

        throw new JsonException ($"{propertyName}: Bad Attribute.");
    }

    public override void Write (Utf8JsonWriter writer, Attribute value, JsonSerializerOptions options)
    {
        writer.WriteStartObject ();
        writer.WritePropertyName (nameof (Attribute.Foreground));
        ColorJsonConverter.Instance.Write (writer, value.Foreground, options);
        writer.WritePropertyName (nameof (Attribute.Background));
        ColorJsonConverter.Instance.Write (writer, value.Background, options);

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Rename the key to one of: Foreground, Background, Style (case-insensitive).
  2. Remove the unrecognized key if it is not needed.
  3. Check the AttributeJsonConverter.Write output to see the canonical key names the library itself emits.

Example fix

// before
{ "Fg": "Red", "Bg": "Black" }
// after
{ "Foreground": "Red", "Background": "Black" }
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> _attrKeys = new (StringComparer.OrdinalIgnoreCase) { "foreground", "background", "style" };
foreach (var p in attr.EnumerateObject ())
    if (!_attrKeys.Contains (p.Name))
        throw new InvalidOperationException ($"Unknown Attribute key: {p.Name}");

Type guard

static bool IsKnownAttributeKey (string key) =>
    key.Equals ("foreground", StringComparison.OrdinalIgnoreCase)
    || key.Equals ("background", StringComparison.OrdinalIgnoreCase)
    || key.Equals ("style", StringComparison.OrdinalIgnoreCase);

Try / catch

try { ConfigurationManager.Apply (); }
catch (JsonException ex) when (ex.Message.Contains ("Unknown Attribute property"))
{ /* remove/rename the unknown key */ }

Prevention

When it happens

Trigger: A config Attribute contains a key like "Color", "Fg", "Bg", "Text", "Width", or any unrecognized property.

Common situations: Using an abbreviation instead of the full name; carrying over a property name from v1 or another theming system; typo ("Forground").

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/369693535b29c709. Report an issue: GitHub.