QuestPDF/QuestPDF · error · ArgumentException

The dash pattern cannot be empty.

Error message

The dash pattern cannot be empty.

What it means

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.

Source

Thrown at src/dotnet/library/QuestPDF/Fluent/LineExtensions.cs:38

        /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="colorParam"]/*' />
        public LineDescriptor LineColor(Color color)
        {
            Line.Color = color;
            return this;
        }

        /// <summary>
        /// Configures a dashed pattern for the line.
        /// For example, a pattern of [2, 3] creates a dash of 2 units followed by a gap of 3 units.
        /// </summary>
        /// <param name="dashPattern">The length of this array must be even.</param>
        public LineDescriptor LineDashPattern(float[] dashPattern, Unit unit = Unit.Point)
        {
            if (dashPattern == null)
                throw new ArgumentNullException(nameof(dashPattern), "The dash pattern cannot be null.");
            
            if (dashPattern.Length == 0)
                throw new ArgumentException("The dash pattern cannot be empty.", nameof(dashPattern));
            
            if (dashPattern.Length % 2 != 0)
                throw new ArgumentException("The dash pattern must contain an even number of elements.", nameof(dashPattern));
            
            Line.DashPattern = dashPattern.Select(x => x.ToPoints(unit)).ToArray();
            return this;
        }

        /// <summary>
        /// Applies a linear gradient to a line using the specified colors.
        /// </summary>
        public LineDescriptor LineGradient(Color[] colors)
        {
            if (colors == null)
                throw new ArgumentNullException(nameof(colors), "The gradient colors cannot be null.");

            if (colors.Length == 0)
                throw new ArgumentException("The gradient colors cannot be empty.", nameof(colors));

View on GitHub (pinned to 43ab125596)

Solutions

  1. Supply a real alternating dash/gap array with even length >= 2, e.g. new[] { 2f, 3f }.
  2. Guard the call site: if (pattern.Length > 0) line.LineDashPattern(pattern); else /* omit or use solid line */.
  3. Validate config at load time and reject empty dash arrays early with a clearer domain error.

Example fix

// before
.Line(l => l.LineDashPattern(pattern)); // pattern.Length == 0

// after
if (pattern is { Length: > 0 })
    .Line(l => l.LineDashPattern(pattern));
Defensive patterns

Strategy: validation

Validate before calling

if (dashPattern is not { Length: > 0 }) return; // skip dash, use solid line
line.LineDashPattern(dashPattern);

Type guard

static bool HasDashEntries(float[] p) => p != null && p.Length > 0;

Prevention

When it happens

Trigger: Calling .LineDashPattern(Array.Empty<float>()) or .LineDashPattern(config.DashPattern.ToArray()) where config.DashPattern is an empty list. The guard is dashPattern.Length == 0.

Common situations: 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.

Related errors


AI-assisted analysis of QuestPDF/QuestPDF@43ab125596 (2026-08-13). Data as JSON: /api/errors/fb99a192dc555644. Report an issue: GitHub.