tui-cs/Terminal.Gui · error · InvalidOperationException
{schemeName}: Does not exist in Schemes.
Error message
{schemeName}: Does not exist in Schemes. What it means
RemoveScheme was called with a name that is neither a built-in scheme nor present in the current schemes dictionary. You can only remove a scheme that was previously added via AddScheme and still exists.
Source
Thrown at Terminal.Gui/Configuration/SchemeManager.cs:105
GetSchemes () [schemeName] = scheme;
}
}
/// <summary>
/// Removes a Scheme from <see cref="SchemeManager"/>.
/// </summary>
/// <param name="schemeName"></param>
/// <exception cref="InvalidOperationException">If the scheme is a built-in Scheme or was not previously added.</exception>
public static void RemoveScheme (string schemeName)
{
if (SchemeNameToSchemes (schemeName) is { })
{
throw new InvalidOperationException ($@"{schemeName}: Cannot remove a built-in Scheme.");
}
if (!GetSchemes ().TryGetValue (schemeName, out _))
{
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]!;
}View on GitHub (pinned to 2e47b11478)
Solutions
- Verify the scheme exists with TryGetScheme or GetSchemes().ContainsKey(name) before removing.
- Guard removal with an existence check.
Example fix
// before
SchemeManager.RemoveScheme ("myTheme");
// after
if (SchemeManager.TryGetScheme ("myTheme", out _))
{
SchemeManager.RemoveScheme ("myTheme");
} Defensive patterns
Strategy: validation
Validate before calling
if (SchemeManager.TryGetScheme (name, out _))
{
SchemeManager.RemoveScheme (name);
} Try / catch
try { SchemeManager.RemoveScheme (name); }
catch (InvalidOperationException ex) when (ex.Message.Contains ("Does not exist"))
{ /* already removed or never added; nothing to do */ } Prevention
- Track added scheme names; avoid blind removals.
- Use TryGetScheme to test before RemoveScheme.
When it happens
Trigger: Calling RemoveScheme with a typo, or removing a scheme that was already removed, or before it was added.
Common situations: Double-removal; cleanup logic that does not track current state; misspelled scheme name.
Related errors
- {schemeName}: Cannot remove a built-in Scheme.
- Invalid scheme name: {schemeName}
- 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/a8dea224257b3dd7.
Report an issue: GitHub.