SubtitleEdit/subtitleedit · warning · ArgumentException

Color '{colorName}' not found in SKColors.

Error message

Color '{colorName}' not found in SKColors.

What it means

ColorTranslator.FromName does case-insensitive reflection over SkiaSharp's SKColors static properties; if no property of type SKColor matches the supplied name, it throws ArgumentException. The library uses this to resolve user-supplied or config-file color strings (e.g. "Red", "LightBlue") into SKColor values.

Source

Thrown at src/libse/Common/ColorTranslator.cs:37

                                string.Equals(f.Name, colorName, StringComparison.OrdinalIgnoreCase));

            if (field != null)
            {
                return (SKColor)field.GetValue(null);
            }

            // Search properties (in case any are defined as such)
            var property = type.GetProperties(BindingFlags.Public | BindingFlags.Static)
                               .FirstOrDefault(p =>
                                   p.PropertyType == typeof(SKColor) &&
                                   string.Equals(p.Name, colorName, StringComparison.OrdinalIgnoreCase));

            if (property != null)
            {
                return (SKColor)property.GetValue(null);
            }

            throw new ArgumentException($"Color '{colorName}' not found in SKColors.");
        }

        public static SKColor FromHtml(string htmlColor)
        {
            return SKColor.TryParse(htmlColor, out var color) ? color : ParseNamedColor(htmlColor);
        }

        public static object ToHtml(SKColor color)
        {
            if (color.Alpha == 255)
            {
                return $"#{color.Red:X2}{color.Green:X2}{color.Blue:X2}";
            }
            else
            {
                return $"#{color.Alpha:X2}{color.Red:X2}{color.Green:X2}{color.Blue:X2}";
            }
        }

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Prefer ColorTranslator.FromHtml which tries SKColor.TryParse first and only falls back to named lookup.
  2. Strip whitespace and trim a trailing ';' before lookup.
  3. Validate the name against SKColors.GetFields()/GetProperties() at app startup to build a known set.
  4. Provide a default/fallback SKColor (e.g. SKColors.Black) when the name is unknown instead of throwing.

Example fix

// before
var property = type.GetProperties(...).FirstOrDefault(p => /* match */);
if (property != null) return (SKColor)property.GetValue(null);
throw new ArgumentException($"Color '{colorName}' not found in SKColors.");

// after
var property = type.GetProperties(...).FirstOrDefault(p => /* match */);
if (property != null) return (SKColor)property.GetValue(null);
return SKColors.Black; // or return false from a Try-pattern
Defensive patterns

Strategy: fallback

Validate before calling

var known = typeof(SKColors).GetProperties().Select(p => p.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
if (!known.Contains(colorName.Trim().TrimEnd(';'))) return SKColors.Black;

Type guard

static bool IsKnownColor(string name) =>
    typeof(SKColors).GetProperties(BindingFlags.Public | BindingFlags.Static)
        .Any(p => p.PropertyType == typeof(SKColor) &&
                  string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));

Try / catch

try { return ColorTranslator.FromName(name); }
catch (ArgumentException) { return SKColors.Black; }

Prevention

When it happens

Trigger: Calling ColorTranslator.FromName / ParseNamedColor with a name that is not an SKColors member (misspelling, HTML name like 'cyan1', CSS name not in SKColors, leading/trailing whitespace, trailing semicolon).

Common situations: Typo in a settings XML/JSON color attribute; migrating from System.Drawing.Color names (which has many more entries than SKColors); locale-specific or vendor-specific color names; user input from a color picker text field.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/90dc96d993d4470d. Report an issue: GitHub.