{"record":{"id":"adb108c3a13b655e","repo":"AvaloniaUI/Avalonia","slug":"invalid-color-string-s","errorCode":null,"errorMessage":"Invalid color string: '{s}'.","messagePattern":"Invalid color string: '(.+?)'\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Color.cs","lineNumber":120,"sourceCode":"\n        /// <summary>\n        /// Parses a color string.\n        /// </summary>\n        /// <param name=\"s\">The color string.</param>\n        /// <returns>The <see cref=\"Color\"/>.</returns>\n        public static Color Parse(string s)\n        {\n            if (s is null)\n            {\n                throw new ArgumentNullException(nameof(s));\n            }\n\n            if (TryParse(s, out Color color))\n            {\n                return color;\n            }\n\n            throw new FormatException($\"Invalid color string: '{s}'.\");\n        }\n\n        /// <summary>\n        /// Parses a color string.\n        /// </summary>\n        /// <param name=\"s\">The color string.</param>\n        /// <returns>The <see cref=\"Color\"/>.</returns>\n        public static Color Parse(ReadOnlySpan<char> s)\n        {\n            if (TryParse(s, out Color color))\n            {\n                return color;\n            }\n\n            throw new FormatException($\"Invalid color string: '{s.ToString()}'.\");\n        }\n\n        /// <summary>","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Color.cs#L102-L138","documentation":"Color.Parse(string) throws FormatException when the input cannot be parsed as a color. Accepted formats include known color names and hex strings (#RGB, #RRGGBB, #AARRGGBB, #RRGGBBAA, and optionally rgb()/rgba()-style). This overload explicitly checks for null first (ArgumentNullException) and only throws FormatException for non-null unparseable strings.","triggerScenarios":"Calling Color.Parse(s) where s is a non-null string that is not a recognized color name or valid hex/rgb format. E.g. \"orang\", \"#12\", \"rgb(a,b,c)\".","commonSituations":"User-supplied or config-file color strings with typos or wrong format. Hardcoded color strings that were edited incorrectly. Interop with another framework's color notation. Trailing whitespace or culture-specific decimal separators.","solutions":["Use Color.TryParse(s, out var color) and handle the false return instead of Parse.","Verify the string matches an accepted format: named color, #RGB, #RRGGBB, #AARRGGBB.","Trim whitespace and validate before parsing user/config input."],"exampleFix":"// before\nvar color = Color.Parse(configValue);\n\n// after\nif (!Color.TryParse(configValue?.Trim(), out var color))\n    color = Colors.Black; // fallback","handlingStrategy":"validation","validationCode":"if (!Color.TryParse(s, out var color))\n    color = Colors.Black; // fallback\n// now color is guaranteed valid","typeGuard":null,"tryCatchPattern":"Color color;\ntry { color = Color.Parse(s); }\ncatch (FormatException) { color = Colors.Black; }","preventionTips":["Use Color.TryParse for any user/config-derived color string.","Trim whitespace and validate hex format before parsing.","Centralize color parsing in one helper to apply consistent fallbacks."],"tags":["color","parsing","media","format"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}