{"record":{"id":"d61d3212dc0acaac","repo":"SixLabors/ImageSharp","slug":"precision-precision-length-must-be-between-0-and-255","errorCode":null,"errorMessage":"Precision {precision.Length} must be between 0 and 255.","messagePattern":"Precision (.+?) must be between 0 and 255\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/PixelFormats/PixelComponentInfo.cs","lineNumber":69,"sourceCode":"    /// <param name=\"precision\">The precision in bits of each component.</param>\n    /// <returns>The <see cref=\"PixelComponentInfo\"/>.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">The component precision and index cannot exceed the component range.</exception>\n    public static PixelComponentInfo Create(int count, int bitsPerPixel, params int[] precision)\n    {\n        if (precision.Length < count || precision.Length > 16)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), $\"Count {count} must match the length of precision array and cannot exceed 16.\");\n        }\n\n        long precisionData1 = 0;\n        long precisionData2 = 0;\n        int sum = 0;\n        for (int i = 0; i < precision.Length; i++)\n        {\n            int p = precision[i];\n            if (p is < 0 or > 255)\n            {\n                throw new ArgumentOutOfRangeException(nameof(precision), $\"Precision {precision.Length} must be between 0 and 255.\");\n            }\n\n            if (i < 8)\n            {\n                precisionData1 |= ((long)p) << (8 * i);\n            }\n            else\n            {\n                precisionData2 |= ((long)p) << (8 * (i - 8));\n            }\n\n            sum += p;\n        }\n\n        return new PixelComponentInfo(count, bitsPerPixel - sum, precisionData1, precisionData2);\n    }\n\n    /// <summary>","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/PixelFormats/PixelComponentInfo.cs#L51-L87","documentation":"Each component precision must fit in one byte (0–255) because PixelComponentInfo packs eight precisions per 64-bit word. Create throws ArgumentOutOfRangeException naming 'precision' when any precision value is negative or greater than 255. (The message interpolates precision.Length rather than the offending value — a known message quirk.)","triggerScenarios":"Calling PixelComponentInfo.Create with a precision array containing a negative number or a value above 255, e.g. bits-per-channel-like values such as 512 or -1.","commonSituations":"Passing bitsPerPixel instead of per-component precision; computing precision from masks or bit counts that exceed a byte; copy-paste errors putting total bits in the array.","solutions":["Clamp/validate each precision to 0..255 before calling Create","Ensure you pass per-component precision (e.g. 8,8,8,8 for 32-bit RGBA), not the total bit depth","Catch ArgumentOutOfRangeException and log the precision array for diagnosis"],"exampleFix":"// before\nPixelComponentInfo.Create(1, 512, 512); // precision > 255\n// after\nPixelComponentInfo.Create(2, 1024, 512, 512); // per-component precisions within 0..255","handlingStrategy":"validation","validationCode":"bool ok = precision.All(p => p is >= 0 and <= 255);","typeGuard":"null","tryCatchPattern":"try { var info = PixelComponentInfo.Create(count, bpp, precision); } catch (ArgumentOutOfRangeException ex) { log.Error(ex, \"Precision values must be 0-255\"); throw; }","preventionTips":["Pass per-component precision, not total bit depth","Clamp precisions to 0..255 before calling","Note the message reports the array length, not the bad value — validate inputs yourself"],"tags":["pixels","pixelformat","argument-out-of-range"],"backgroundTag":"value-out-of-range","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"}