{"record":{"id":"fb99a192dc555644","repo":"QuestPDF/QuestPDF","slug":"the-dash-pattern-cannot-be-empty","errorCode":null,"errorMessage":"The dash pattern cannot be empty.","messagePattern":"The dash pattern cannot be empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs","lineNumber":38,"sourceCode":"        /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for=\"colorParam\"]/*' />\n        public LineDescriptor LineColor(Color color)\n        {\n            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));","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/QuestPDF/QuestPDF/blob/43ab12559671556e10a6a0a5afe542c919f48a21/src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs#L20-L56","documentation":"Thrown by LineDescriptor.LineDashPattern when dashPattern is a zero-length array. An empty sequence defines no dash/gap pairs, so there is nothing for the PDF stroke to render; QuestPDF rejects it with an ArgumentException after the null check passes.","triggerScenarios":"Calling .LineDashPattern(Array.Empty<float>()) or .LineDashPattern(config.DashPattern.ToArray()) where config.DashPattern is an empty list. The guard is dashPattern.Length == 0.","commonSituations":"Mapping a user-editable config list that the user left empty; building the array from a filtered source whose predicate matched nothing; defaulting to new float[]{} instead of a real pattern.","solutions":["Supply a real alternating dash/gap array with even length >= 2, e.g. new[] { 2f, 3f }.","Guard the call site: if (pattern.Length > 0) line.LineDashPattern(pattern); else /* omit or use solid line */.","Validate config at load time and reject empty dash arrays early with a clearer domain error."],"exampleFix":"// before\n.Line(l => l.LineDashPattern(pattern)); // pattern.Length == 0\n\n// after\nif (pattern is { Length: > 0 })\n    .Line(l => l.LineDashPattern(pattern));","handlingStrategy":"validation","validationCode":"if (dashPattern is not { Length: > 0 }) return; // skip dash, use solid line\nline.LineDashPattern(dashPattern);","typeGuard":"static bool HasDashEntries(float[] p) => p != null && p.Length > 0;","tryCatchPattern":null,"preventionTips":["Default optional dash config to a real pair like [2f, 3f] instead of empty.","Reject empty dash arrays at the config boundary with a domain error.","Treat an empty array as 'no dash' and skip the call instead of passing it through."],"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"}