{"record":{"id":"062bd4a89c6b3ae5","repo":"QuestPDF/QuestPDF","slug":"the-gradient-colors-cannot-be-null","errorCode":null,"errorMessage":"The gradient colors cannot be null.","messagePattern":"The gradient colors cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs","lineNumber":53,"sourceCode":"                throw new ArgumentNullException(nameof(dashPattern), \"The dash pattern cannot be null.\");\n            \n            if (dashPattern.Length == 0)\n                throw new ArgumentException(\"The dash pattern cannot be empty.\", nameof(dashPattern));\n            \n            if (dashPattern.Length % 2 != 0)\n                throw new ArgumentException(\"The dash pattern must contain an even number of elements.\", nameof(dashPattern));\n            \n            Line.DashPattern = dashPattern.Select(x => x.ToPoints(unit)).ToArray();\n            return this;\n        }\n\n        /// <summary>\n        /// Applies a linear gradient to a line using the specified colors.\n        /// </summary>\n        public LineDescriptor LineGradient(Color[] colors)\n        {\n            if (colors == null)\n                throw new ArgumentNullException(nameof(colors), \"The gradient colors cannot be null.\");\n\n            if (colors.Length == 0)\n                throw new ArgumentException(\"The gradient colors cannot be empty.\", nameof(colors));\n\n            Line.GradientColors = colors;\n            return this;\n        }\n    }\n    \n    public static class LineExtensions\n    {\n        private static LineDescriptor Line(this IContainer element, LineType type, float thickness)\n        {\n            if (thickness < 0)\n                throw new ArgumentOutOfRangeException(nameof(thickness), \"The Line thickness cannot be negative.\");\n            \n            var descriptor = new LineDescriptor();\n            descriptor.Line.Thickness = thickness;","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/QuestPDF/QuestPDF/blob/43ab12559671556e10a6a0a5afe542c919f48a21/src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs#L35-L71","documentation":"Thrown by LineDescriptor.LineGradient when the colors argument is null. A gradient needs at least two color stops to interpolate, so a null Color[] cannot be applied and is rejected with an ArgumentNullException before the length check.","triggerScenarios":"Calling .LineGradient(null) or passing a colors array that was never populated (e.g. a palette lookup that returned null). Guard: if (colors == null).","commonSituations":"Theme/palette service returns null when a key is missing; JSON config binds an optional colors array to null; conditional palette construction skipped the assignment branch.","solutions":["Pass a non-empty Color[], e.g. LineGradient(new[] { Colors.Blue, Colors.Red }).","Coalesce from a default palette: colors ?? Theme.DefaultGradient.","Make the palette accessor return an empty/default array instead of null."],"exampleFix":"// before\n.Line(l => l.LineGradient(palette)); // palette is null\n\n// after\n.Line(l => l.LineGradient(palette ?? new[] { Colors.Grey.Lighten2, Colors.Grey.Darken2 }));","handlingStrategy":"validation","validationCode":"colors ??= new[] { Colors.Grey.Lighten2, Colors.Grey.Darken2 };\nline.LineGradient(colors);","typeGuard":"static bool HasGradientColors(Color[]? c) => c is { Length: > 0 };","tryCatchPattern":null,"preventionTips":["Make palette services return an empty array instead of null.","Coalesce optional palette config to a default pair.","Enable nullable reference types to catch null palettes at compile time."],"tags":["questpdf","argument-null","validation","line","gradient","csharp"],"backgroundTag":null,"analyzedSha":"43ab12559671556e10a6a0a5afe542c919f48a21","analyzedAt":"2026-08-13T17:02:41.303Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}