{"record":{"id":"20c70ffcf956d366","repo":"SixLabors/ImageSharp","slug":"color","errorCode":null,"errorMessage":"color","messagePattern":"color","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs","lineNumber":868,"sourceCode":"\n        static int GetQualityForTable(int destIndex, int? encoderQuality, JpegMetadata metadata) => destIndex switch\n        {\n            0 => encoderQuality ?? metadata.LuminanceQuality ?? Quantization.DefaultQualityFactor,\n            1 => encoderQuality ?? metadata.ChrominanceQuality ?? Quantization.DefaultQualityFactor,\n            _ => encoderQuality ?? metadata.Quality,\n        };\n    }\n\n    private JpegFrameConfig GetFrameConfig(JpegMetadata metadata)\n    {\n        JpegColorType color = this.encoder.ColorType ?? metadata.ColorType;\n        JpegFrameConfig frameConfig = Array.Find(\n            FrameConfigs,\n            cfg => cfg.EncodingColor == color);\n\n        if (frameConfig == null)\n        {\n            throw new ArgumentException(nameof(color));\n        }\n\n        return frameConfig;\n    }\n}\n","sourceCodeStart":850,"sourceCodeEnd":874,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs#L850-L874","documentation":"JpegEncoderCore looks up the preconfigured JpegFrameConfig matching the requested JpegEncodingColor in the static FrameConfigs table. If no entry exists for the given color value, it throws ArgumentException — though the message passes the parameter name ('color') rather than a descriptive message, indicating an unexpected/unsupported color mode reached the encoder core.","triggerScenarios":"Calling Save/SaveAsync with a JpegEncoder whose ColorType (JpegEncodingColor) is a value with no corresponding FrameConfig entry — e.g. a default(JpegEncodingColor) of 0 or an invalid cast of an integer/enum from configuration that is not one of the defined encoding colors (YCbCr, Rgb, Luminance, etc.).","commonSituations":"Binding ColorType from a config string/number without parsing to the enum; using (JpegEncodingColor)someInt casts; library version changes where a color mode was added/removed and serialized options no longer match; generic encoder wrappers passing default enum values.","solutions":["Set ColorType to a valid JpegEncodingColor member (e.g. JpegEncodingColor.YCbCr) instead of a raw cast or default value.","If the value comes from configuration/user input, parse it with Enum.TryParse and reject unknown values.","Update ImageSharp to a version that supports the desired color mode if you are using a newly added JpegEncodingColor on an older package."],"exampleFix":"// before\nvar encoder = new JpegEncoder { ColorType = (JpegEncodingColor)configValue };\n// after\nif (!Enum.TryParse(configValue, out JpegEncodingColor colorType))\n    colorType = JpegEncodingColor.YCbCr;\nvar encoder = new JpegEncoder { ColorType = colorType };","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(JpegEncodingColor), colorType))\n    colorType = JpegEncodingColor.YCbCr;\nvar encoder = new JpegEncoder { ColorType = colorType };","typeGuard":"static bool IsDefinedColor(JpegEncodingColor c) => Enum.IsDefined(typeof(JpegEncodingColor), c) && c != default;","tryCatchPattern":"try\n{\n    image.Save(path, encoder);\n}\ncatch (ArgumentException ex) when (ex.Message == nameof(JpegEncodingColor))\n{\n    // invalid ColorType; retry with default\n}","preventionTips":["Never cast raw ints to JpegEncodingColor; parse config strings with Enum.TryParse.","Avoid default(JpegEncodingColor) (value 0) — it is not a valid encoding color.","Re-validate persisted encoder options after upgrading ImageSharp versions."],"tags":["jpeg","encoder","enum","argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}