{"record":{"id":"3573337d600bbd8e","repo":"dotnet/wpf","slug":"sr-thememode-value-0-is-invalid-use-none-system-light-or","errorCode":null,"errorMessage":"SR.ThemeMode value {0} is invalid. Use None, System, Light or Dark","messagePattern":"SR\\.ThemeMode value (.+?) is invalid\\. Use None, System, Light or Dark","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs","lineNumber":586,"sourceCode":"        ///\n        ///     This property is experimental and may be removed in future versions.\n        /// </remarks>\n        [Experimental(\"WPF0001\")]\n        [TypeConverter(typeof(ThemeModeConverter))]\n        public ThemeMode ThemeMode\n        {\n            get\n            {\n                VerifyContextAndObjectState();\n                return _themeMode;\n            }\n            set\n            {\n                VerifyContextAndObjectState();\n\n                if(!ThemeManager.IsValidThemeMode(value))\n                {\n                    throw new ArgumentException(string.Format(\"ThemeMode value {0} is invalid. Use None, System, Light or Dark\", value));\n                }\n\n                ThemeMode oldTheme = _themeMode;\n                _themeMode = value;\n\n                if(!AreResourcesInitialized)\n                {\n                    ThemeManager.OnWindowThemeChanged(this, oldTheme, value);\n                    AreResourcesInitialized = false;\n\n                    _reloadFluentDictionary = true;\n                }\n\n                if(IsSourceWindowNull)\n                {\n                    _deferThemeLoading = true;\n                }\n                else","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L568-L604","documentation":"The Window.ThemeMode property setter validates the requested theme value against ThemeManager.IsValidThemeMode. Passing anything other than None, System, Light, or Dark throws an ArgumentException with the message \"ThemeMode value {0} is invalid. Use None, System, Light or Dark\".","triggerScenarios":"Setting window.ThemeMode (in code or XAML) to a string/value not among None, System, Light, Dark - e.g. a typo like \"Darkd\", \"dark\" with different casing if not accepted, or a bound value from configuration.","commonSituations":"Loading the theme from a settings file or user preference that contains an unsupported name; typos in XAML attributes; binding ThemeMode to a free-form string property.","solutions":["Set ThemeMode to exactly one of None, System, Light, Dark","Validate/sanitize the persisted theme setting before assigning it","Parse user/config input into a strongly typed enum with TryParse before applying","Add app-level fallback to System for unrecognized values"],"exampleFix":"// before\nwindow.ThemeMode = config[\"theme\"]; // \"midnight\" -> ArgumentException\n// after\nvar mode = Enum.TryParse(config[\"theme\"], true, out ThemeMode m) ? m : ThemeMode.System;\nwindow.ThemeMode = mode;","handlingStrategy":"validation","validationCode":"string[] valid = { \"None\", \"System\", \"Light\", \"Dark\" };\nif (!valid.Contains(themeValue)) themeValue = \"System\";","typeGuard":"bool IsValidThemeMode(string s) => s is \"None\" or \"System\" or \"Light\" or \"Dark\";","tryCatchPattern":"try { window.ThemeMode = value; } catch (ArgumentException ex) when (ex.Message.Contains(\"ThemeMode\")) { window.ThemeMode = \"System\"; }","preventionTips":["Validate persisted theme settings against the allowed set","Use a strongly typed enum for theme values","Fall back to System on unknown input"],"tags":["wpf","window","theme","argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}