{"record":{"id":"399c7d0324b5db31","repo":"QuestPDF/QuestPDF","slug":"the-dash-pattern-must-contain-an-even-number-of-el","errorCode":null,"errorMessage":"The dash pattern must contain an even number of elements.","messagePattern":"The dash pattern must contain an even number of elements\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs","lineNumber":41,"sourceCode":"            Line.Color = color;\n            return this;\n        }\n\n        /// <summary>\n        /// Configures a dashed pattern for the line.\n        /// For example, a pattern of [2, 3] creates a dash of 2 units followed by a gap of 3 units.\n        /// </summary>\n        /// <param name=\"dashPattern\">The length of this array must be even.</param>\n        public LineDescriptor LineDashPattern(float[] dashPattern, Unit unit = Unit.Point)\n        {\n            if (dashPattern == null)\n                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;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/QuestPDF/QuestPDF/blob/43ab12559671556e10a6a0a5afe542c919f48a21/src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs#L23-L59","documentation":"Thrown by LineDescriptor.LineDashPattern when dashPattern has an odd number of elements. QuestPDF consumes the array as alternating (dash, gap) pairs, so an odd length leaves a dangling dash with no gap; the guard dashPattern.Length % 2 != 0 rejects it with an ArgumentException.","triggerScenarios":"Passing new[] { 2f, 3f, 4f } (3 elements) or any odd-length array. Common when a user supplies a flat list of dash lengths and forgets gaps must be interleaved.","commonSituations":"Config authored as \"2,3,4\" (intended as three dashes) rather than the required dash-gap-dash-gap form; data binding from a UI that collects dash sizes only.","solutions":["Provide pairs: every odd index is a gap. Minimum valid is two elements, e.g. new[] { 2f, 3f }.","If your data is dash-only, interleave a default gap: pattern.SelectMany(d => new[] { d, gap }).ToArray().","Add a config-time assertion that pattern.Length % 2 == 0 with a domain-specific message."],"exampleFix":"// before\n.Line(l => l.LineDashPattern(new[] { 2f, 3f, 4f })); // 3 elements, odd\n\n// after\n.Line(l => l.LineDashPattern(new[] { 2f, 3f, 4f, 3f })); // dash-gap-dash-gap","handlingStrategy":"validation","validationCode":"if (dashPattern.Length % 2 != 0)\n    throw new InvalidOperationException($\"Dash pattern must have an even count, got {dashPattern.Length}.\");\nline.LineDashPattern(dashPattern);","typeGuard":"static bool IsEvenLength(float[] p) => p != null && p.Length % 2 == 0;","tryCatchPattern":null,"preventionTips":["Document dash patterns as dash-gap-dash-gap to users editing config.","Assert even length at config load time.","If collecting dash-only sizes, interleave a gap programmatically."],"tags":["questpdf","argument","validation","line","csharp"],"backgroundTag":null,"analyzedSha":"43ab12559671556e10a6a0a5afe542c919f48a21","analyzedAt":"2026-08-13T17:02:41.303Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}