{"record":{"id":"fb0d8c76b17ad7c7","repo":"tui-cs/Terminal.Gui","slug":"schemename-cannot-remove-a-built-in-scheme","errorCode":null,"errorMessage":"{schemeName}: Cannot remove a built-in Scheme.","messagePattern":"(.+?): Cannot remove a built-in Scheme\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/SchemeManager.cs","lineNumber":100,"sourceCode":"    /// <returns></returns>\n    public static void AddScheme (string schemeName, Scheme scheme)\n    {\n        if (!GetSchemes ().TryAdd (schemeName, scheme))\n        {\n            GetSchemes () [schemeName] = scheme;\n        }\n    }\n\n    /// <summary>\n    ///     Removes a Scheme from <see cref=\"SchemeManager\"/>.\n    /// </summary>\n    /// <param name=\"schemeName\"></param>\n    /// <exception cref=\"InvalidOperationException\">If the scheme is a built-in Scheme or was not previously added.</exception>\n    public static void RemoveScheme (string schemeName)\n    {\n        if (SchemeNameToSchemes (schemeName) is { })\n        {\n            throw new InvalidOperationException ($@\"{schemeName}: Cannot remove a built-in Scheme.\");\n        }\n\n        if (!GetSchemes ().TryGetValue (schemeName, out _))\n        {\n            throw new InvalidOperationException ($@\"{schemeName}: Does not exist in Schemes.\");\n        }\n\n        GetSchemes ().Remove (schemeName);\n    }\n\n    /// <summary>\n    ///     Gets the <see cref=\"Scheme\"/> for the specified <see cref=\"Drawing.Schemes\"/>.\n    /// </summary>\n    /// <param name=\"schemeName\"></param>\n    /// <returns></returns>\n    /// <exception cref=\"ArgumentException\"></exception>\n    public static Scheme GetScheme (Schemes schemeName)\n    {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/SchemeManager.cs#L82-L118","documentation":"RemoveScheme rejects names that map to a built-in Schemes enum value (SchemeNameToSchemes returns non-null). Built-in schemes (e.g. TopLevel, Dialog, Menu, Error) are protected and cannot be removed — only modified.","triggerScenarios":"Calling SchemeManager.RemoveScheme(\"TopLevel\") or any other built-in scheme name.","commonSituations":"App code that dynamically manages schemes and tries to clean up a built-in; generic \"remove all schemes\" cleanup logic.","solutions":["Do not remove built-in schemes; modify them in place via AddScheme (which updates an existing name).","Filter out built-in names (SchemeNameToSchemes(name) != null) before calling RemoveScheme."],"exampleFix":"// before\nSchemeManager.RemoveScheme (\"Dialog\");\n// after\n// built-ins cannot be removed; update in place instead\nSchemeManager.AddScheme (\"Dialog\", myScheme);","handlingStrategy":"validation","validationCode":"static bool IsRemovable (string name) =>\n    SchemeManager.SchemeNameToSchemes (name) is null;","typeGuard":null,"tryCatchPattern":"try { SchemeManager.RemoveScheme (name); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains (\"Cannot remove a built-in\"))\n{ /* name is a built-in; modify via AddScheme instead */ }","preventionTips":["Treat built-in scheme names as read-only for removal.","Use SchemeNameToSchemes to test whether a name is built-in before removing."],"tags":["config","scheme","runtime-api"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}