tui-cs/Terminal.Gui · error · InvalidOperationException
Current Theme does not have a Scheme.
Error message
Current Theme does not have a Scheme.
What it means
GetSchemesForCurrentTheme reads the active theme's "Schemes" config property and expects a Dictionary<string,Scheme?>. If the property value is null or not that dictionary type — typically because the "Schemes" key was omitted from the theme config — this InvalidOperationException is thrown.
Source
Thrown at Terminal.Gui/Configuration/SchemeManager.cs:222
}
/// <summary>
/// Get the dictionary of schemes from the current theme. Current means active.
/// </summary>
/// <returns></returns>
public static Dictionary<string, Scheme?> GetSchemesForCurrentTheme ()
{
lock (_schemesLock)
{
if (!ConfigurationManager.IsInitialized ())
{
throw new InvalidOperationException ("CM Must be Initialized");
}
if (ThemeManager.GetCurrentTheme () ["Schemes"].PropertyValue is not Dictionary<string, Scheme?> schemes)
{
// Most likely because "Schemes": was left out of the config
throw new InvalidOperationException ("Current Theme does not have a Scheme.");
}
return schemes;
}
}
/// <summary>
/// Convenience method to get the names of the schemes.
/// </summary>
/// <returns></returns>
public static ImmutableList<string> GetSchemeNames ()
{
lock (_schemesLock)
{
return GetSchemes ().Keys.ToImmutableList ();
}
}
View on GitHub (pinned to 2e47b11478)
Solutions
- Ensure the theme JSON includes a "Schemes" object (copy the Schemes block from the default theme).
- Load a complete theme via ThemeManager, or add schemes via AddScheme.
- Use TryGetScheme (which returns false instead of throwing) when absence is expected.
Example fix
// before
{ "Theme": { "Name": "MyTheme" } }
// after
{ "Theme": { "Name": "MyTheme", "Schemes": { "Base": { "Normal": { "Foreground": "White" } } } } } Defensive patterns
Strategy: validation
Validate before calling
bool themesHasSchemes =
ThemeManager.GetCurrentTheme () ["Schemes"].PropertyValue
is Dictionary<string, Scheme?>; Try / catch
try { var schemes = SchemeManager.GetSchemesForCurrentTheme (); }
catch (InvalidOperationException ex) when (ex.Message.Contains ("does not have a Scheme"))
{ /* theme omitted the Schemes block; fall back to AddScheme or load a full theme */ } Prevention
- Always include a Schemes block in custom themes.
- Prefer TryGetScheme over GetScheme when absence is possible.
When it happens
Trigger: A theme config JSON that defines settings but omits the "Schemes" object entirely; a partially-applied theme; calling GetSchemesForCurrentTheme before the theme's Schemes were populated.
Common situations: Custom theme missing the Schemes section; upgrading without including the required Schemes block; ConfigurationManager.Apply on a config lacking Schemes.
Related errors
- Unexpected StartObject token when parsing Scheme: {reader.To
- After {propertyName}: Expected Attribute but got {attrObj?.G
- {propertyName}: Unrecognized Scheme Attribute name.
- {schemeName}: Cannot remove a built-in Scheme.
- {schemeName}: Does not exist in Schemes.
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/870ce6b0d5f64aea.
Report an issue: GitHub.