tui-cs/Terminal.Gui · error · JsonException

Invalid TraceCategory value in array: '{value}'

Error message

Invalid TraceCategory value in array: '{value}'

What it means

Thrown by TraceCategoryJsonConverter.Read while parsing the array form when an element IS a string but Enum.TryParse fails to map it to a TraceCategory member (case-insensitive). This is the per-element analog of error 90: at least one name in the array is invalid.

Source

Thrown at Terminal.Gui/Configuration/TraceCategoryJsonConverter.cs:57

            {
                if (reader.TokenType == JsonTokenType.EndArray)
                {
                    break;
                }

                if (reader.TokenType != JsonTokenType.String)
                {
                    throw new JsonException ($"Unexpected token type in TraceCategory array: {reader.TokenType}");
                }
                string value = reader.GetString ()!;

                if (Enum.TryParse (value, true, out TraceCategory category))
                {
                    result |= category;
                }
                else
                {
                    throw new JsonException ($"Invalid TraceCategory value in array: '{value}'");
                }
            }

            return result;
        }

        throw new JsonException ($"Unexpected token type for TraceCategory: {reader.TokenType}");
    }

    public override void Write (Utf8JsonWriter writer, TraceCategory value, JsonSerializerOptions options)
    {
        if (value == TraceCategory.None)
        {
            writer.WriteStringValue ("None");

            return;
        }

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Correct the offending element to a valid TraceCategory member name (the error message echoes the bad value in quotes).
  2. Check the current TraceCategory enum definition for the available names.
  3. Drop the invalid element entirely if it's no longer relevant.

Example fix

// before
"TraceCategory": ["Command", "Mose"]
// after
"TraceCategory": ["Command", "Mouse"]
Defensive patterns

Strategy: validation

Validate before calling

bool AllValidNames (JsonElement el)
    => el.EnumerateArray ().All (e => e.ValueKind == JsonValueKind.String && Enum.TryParse<TraceCategory> (e.GetString (), true, out _));

Type guard

static bool IsValidTraceCategory (string value) => Enum.TryParse<TraceCategory> (value, true, out _);

Try / catch

ConfigurationManager.ThrowOnJsonErrors = false;

Prevention

When it happens

Trigger: A TraceCategory array containing a typo or unknown name, e.g. ["Command","Mose"] or ["Command","Drawing"] when Drawing isn't a member.

Common situations: Misspelling one element of a multi-category list; referencing a category removed/renamed in a newer Terminal.Gui version.

Related errors


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