tui-cs/Terminal.Gui · error · JsonException

Expected a valid text style value.

Error message

Expected a valid text style value.

What it means

Thrown by AttributeJsonConverter.Read after Enum.Parse<TextStyle> raised ArgumentException because the Style string did not match any TextStyle enum member (case-insensitive). Inner exception is the original ArgumentException. The wrapper message is fixed text (the propertyName context is added by the outer catch at line 104).

Source

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

                        break;
                    case "background":
                        background = JsonSerializer.Deserialize (ref reader, TuiSerializerContext.Instance.Color);

                        break;
                    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)

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Check the TextStyle enum members for your Terminal.Gui version and use an exact name (e.g. Bold, Italic, Underline, Strikethrough, None).
  2. If combining styles, use the format the Enum.Parse call accepts (comma-separated names for [Flags] enums).
  3. Update the config to a known TextStyle name and reload.

Example fix

// before
"Style": "Heavvy"
// after
"Style": "Bold"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate that the Style string is a real TextStyle member.
string styleStr = attr.GetProperty ("Style").GetString ()!;
if (!Enum.TryParse<TextStyle> (styleStr, ignoreCase: true, out _))
    throw new ArgumentOutOfRangeException (nameof (styleStr), $"Unknown TextStyle: {styleStr}");

Type guard

static bool IsValidTextStyle (string s) => Enum.TryParse<TextStyle> (s, ignoreCase: true, out _);

Try / catch

try { ConfigurationManager.Apply (); }
catch (JsonException ex) when (ex.Message.Contains ("valid text style value"))
{ /* replace the bad style name */ }

Prevention

When it happens

Trigger: A config Attribute has a Style value like "Bold2", "Heavy", "Struck" — any string that is not a valid TextStyle member.

Common situations: Typo in a hand-edited config; using a style name from another library (e.g. CSS font-weight words) instead of Terminal.Gui's TextStyle names; version mismatch where a TextStyle member was renamed or removed.

Related errors


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