tui-cs/Terminal.Gui · error · ArgumentException
Invalid scheme name: {schemeName}
Error message
Invalid scheme name: {schemeName} What it means
GetScheme(Schemes) converts the enum to its name via SchemesToSchemeName (Enum.GetName). If the enum value is not a defined member (e.g. (Schemes)999 cast from an unchecked int), Enum.GetName returns null and this ArgumentException is thrown.
Source
Thrown at Terminal.Gui/Configuration/SchemeManager.cs:122
{
throw new InvalidOperationException ($@"{schemeName}: Does not exist in Schemes.");
}
GetSchemes ().Remove (schemeName);
}
/// <summary>
/// Gets the <see cref="Scheme"/> for the specified <see cref="Drawing.Schemes"/>.
/// </summary>
/// <param name="schemeName"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static Scheme GetScheme (Schemes schemeName)
{
// Convert schemeName to string via Enum api
string? schemeNameString = SchemesToSchemeName (schemeName);
return schemeNameString is null ? throw new ArgumentException ($"Invalid scheme name: {schemeName}") : GetSchemesForCurrentTheme () [schemeNameString]!;
}
/// <summary>
/// Gets the <see cref="Scheme"/> for the specified string.
/// </summary>
/// <param name="schemeName"></param>
/// <returns></returns>
/// <exception cref="KeyNotFoundException">If <paramref name="schemeName"/> is not found in the current theme.</exception>
public static Scheme GetScheme (string schemeName) => GetSchemesForCurrentTheme () [schemeName]!;
/// <summary>
/// Attempts to get the <see cref="Scheme"/> for the specified name without throwing.
/// Returns <see langword="false"/> and sets <paramref name="scheme"/> to <see langword="null"/> if the scheme is
/// not found, or if the configuration is not in a state where schemes can be resolved.
/// </summary>
/// <param name="schemeName">The name of the scheme to retrieve.</param>
/// <param name="scheme">
/// When this method returns <see langword="true"/>, contains the resolved <see cref="Scheme"/>; otherwiseView on GitHub (pinned to 2e47b11478)
Solutions
- Validate the enum value with Enum.IsDefined(typeof(Schemes), value) before calling GetScheme.
- Use a known Schemes member (e.g. Schemes.TopLevel).
Example fix
// before
SchemeManager.GetScheme ((Schemes)999);
// after
Schemes s = (Schemes)999;
if (Enum.IsDefined (typeof (Schemes), s))
{
SchemeManager.GetScheme (s);
} Defensive patterns
Strategy: validation
Validate before calling
static bool IsDefinedScheme (Schemes s) => Enum.IsDefined (typeof (Schemes), s);
Try / catch
try { var scheme = SchemeManager.GetScheme (s); }
catch (ArgumentException ex) when (ex.Message.Contains ("Invalid scheme name"))
{ /* s is not a defined Schemes member */ } Prevention
- Always validate enum inputs with Enum.IsDefined before use.
- For user-supplied names, prefer the string-based GetScheme/TryGetScheme.
When it happens
Trigger: Calling GetScheme((Schemes)999) or GetScheme((Schemes)(-1)) — an enum value outside the defined Schemes members.
Common situations: Casting an unchecked integer to Schemes; deserializing an invalid numeric scheme id; arithmetic on enum values producing undefined members.
Related errors
- {schemeName}: Cannot remove a built-in Scheme.
- {schemeName}: Does not exist in Schemes.
- Current Theme does not have a Scheme.
- Unexpected StartObject token when parsing Scheme: {reader.To
- After {propertyName}: Expected PropertyName but got another
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/50b0d9cc37233298.
Report an issue: GitHub.