{"record":{"id":"bbeb263bb5b572ba","repo":"tui-cs/Terminal.Gui","slug":"maximum-sixel-palette-colors-must-be-greater-than","errorCode":null,"errorMessage":"Maximum sixel palette colors must be greater than zero.","messagePattern":"Maximum sixel palette colors must be greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/ImageView/ImageView.cs","lineNumber":220,"sourceCode":"        }\n    }\n\n    /// <summary>\n    ///     Gets or sets the maximum number of colors to use when encoding ImageView sixel output.\n    /// </summary>\n    /// <remarks>\n    ///     The default is 64 colors to keep interactive ImageView redraws responsive. The effective\n    ///     encoder palette is also limited by <see cref=\"SixelSupportResult.MaxPaletteColors\"/> and by\n    ///     the configured <see cref=\"SixelEncoder.Quantizer\"/> <c>MaxColors</c>.\n    /// </remarks>\n    public int MaxSixelPaletteColors\n    {\n        get;\n        set\n        {\n            if (value <= 0)\n            {\n                throw new ArgumentOutOfRangeException (nameof (value), @\"Maximum sixel palette colors must be greater than zero.\");\n            }\n\n            if (field == value)\n            {\n                return;\n            }\n\n            field = value;\n            InvalidateScaledImage ();\n        }\n    } = DEFAULT_MAX_SIXEL_PALETTE_COLORS;\n\n    /// <summary>\n    ///     Gets or sets whether sixel rendering may upscale the visible image region above its source pixel size.\n    /// </summary>\n    /// <remarks>\n    ///     The default is <see langword=\"true\"/> so the image fills the Viewport at <see cref=\"ZoomLevel\"/> 1.\n    ///     Set to <see langword=\"false\"/> to avoid encoding more pixels than the source image provides during fit-to-view","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/ImageView/ImageView.cs#L202-L238","documentation":"Thrown by the ImageView.MaxSixelPaletteColors setter when value <= 0. The property caps how many colors the sixel encoder will quantise the image into during redraws; zero or negative makes quantisation undefined, so it is rejected before the field is updated and InvalidateScaledImage is called. Default is DEFAULT_MAX_SIXEL_PALETTE_COLORS (64).","triggerScenarios":"Setting MaxSixelPaletteColors to 0 or a negative int, often from a config value, a computed count from an empty collection (.Count on an empty palette), or an off-by-one.","commonSituations":"Theme/config JSON feeding 0 when the key is missing; deriving the value from detected terminal palette size before detection completed (returned 0); unit test with an unset field defaulting to 0.","solutions":["Set a positive value (1..256 typically): imageView.MaxSixelPaletteColors = Math.Max(16, detectedColors);","Coerce config input: var colors = configSection.Colors > 0 ? configSection.Colors : 64;","If deriving from capability detection, fall back to the default when detection returns 0/null."],"exampleFix":"// before\nimageView.MaxSixelPaletteColors = detected.MaxColors; // 0 when detection failed\n\n// after\nimageView.MaxSixelPaletteColors = detected is { MaxColors: > 0 } d ? d.MaxColors : 64;","handlingStrategy":"validation","validationCode":"int colors = config.Colors > 0 ? config.Colors : 64;\nimageView.MaxSixelPaletteColors = colors;","typeGuard":"static bool IsValidPaletteSize(int n) => n > 0;","tryCatchPattern":null,"preventionTips":["Coerce config-derived values with a positive fallback before assigning.","Treat 0 from capability detection as 'use default'.","Bound the field initialiser to the DEFAULT constant, not 0."],"tags":["imageview","sixel","validation","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}