{"record":{"id":"085a1021b1feec99","repo":"SixLabors/ImageSharp","slug":"count-count-must-match-the-length-of-precision-array-and","errorCode":null,"errorMessage":"Count {count} must match the length of precision array and cannot exceed 16.","messagePattern":"Count (.+?) must match the length of precision array and cannot exceed 16\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/PixelFormats/PixelComponentInfo.cs","lineNumber":58,"sourceCode":"    /// <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<TPixel>(int count, params int[] precision)\n        where TPixel : unmanaged, IPixel<TPixel>\n        => Create(count, Unsafe.SizeOf<TPixel>() * 8, precision);\n\n    /// <summary>\n    /// Creates a new <see cref=\"PixelComponentInfo\"/> instance.\n    /// </summary>\n    /// <param name=\"count\">The number of components within the pixel format.</param>\n    /// <param name=\"bitsPerPixel\">The number of bits per pixel.</param>\n    /// <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","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/PixelFormats/PixelComponentInfo.cs#L40-L76","documentation":"PixelComponentInfo.Create packs per-component precision values into two 64-bit words, so it accepts at most 16 components and requires a precision entry for every component. When the precision array is shorter than count or longer than 16, it throws ArgumentOutOfRangeException naming 'count'.","triggerScenarios":"Calling PixelComponentInfo.Create(count, bitsPerPixel, precision...) where precision.Length < count (missing entries) or precision.Length > 16 (too many components).","commonSituations":"Defining a custom pixel format with more than 16 channels; forgetting a precision entry for one component (e.g. passing 3 precisions for RGBA); generating precision arrays programmatically with an off-by-one.","solutions":["Pass exactly one precision value per component and keep the total at 16 or fewer","Ensure the params array length equals count before calling","If more than 16 components are needed, split into multiple pixel structures — the format cannot represent it","Catch ArgumentOutOfRangeException from format-creation code and surface which precision array was malformed"],"exampleFix":"// before\nPixelComponentInfo.Create(4, 32, 8, 8, 8); // one short\n// after\nPixelComponentInfo.Create(4, 32, 8, 8, 8, 8);","handlingStrategy":"validation","validationCode":"bool ok = precision is { Length: >= 1 and <= 16 } && precision.Length == count;","typeGuard":"null","tryCatchPattern":"try { var info = PixelComponentInfo.Create(count, bitsPerPixel, precision); } catch (ArgumentOutOfRangeException ex) { throw new InvalidOperationException(\"Precision array must match component count (max 16)\", ex); }","preventionTips":["Always pass one precision per component","Never define custom pixel formats with more than 16 components","Assert precision.Length == count in format-creation helpers"],"tags":["pixels","pixelformat","argument-out-of-range"],"backgroundTag":"argument-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"}