stride3d/stride · error · ArgumentException

points and texts must have the same number of elements.

Error message

points and texts must have the same number of elements.

What it means

DrawTexts pairs each point with a text label, so the points and texts collections must contain the same number of elements. The library throws ArgumentException when their counts differ, because element-wise pairing would be ambiguous.

Solutions

  1. Rebuild both lists in the same loop so they always stay the same length.
  2. Assert/verify points.Count == texts.Count before the call.
  3. If some points have no label, pad texts with empty strings instead of omitting entries.

Example fix

// before
var texts = labels.Where(l => l.Visible).ToList(); // filtered, points not filtered
renderer.DrawTexts(points, color, texts, ...);
// after
var texts = points.Select((p, i) => labels[i].Visible ? labels[i].Text : "").ToList();
renderer.DrawTexts(points, color, texts, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (points == null || texts == null || points.Count != texts.Count) throw new ArgumentException("points and texts must be the same length");

Try / catch

try { renderer.DrawTexts(points, color, texts, ...); } catch (ArgumentException ex) { /* rebuild lists together, log mismatch */ }

Prevention

When it happens

Trigger: Calling DrawTexts where points.Count != texts.Count, e.g. filtering labels after computing points, or appending items to one list but not the other.

Common situations: Filtering out invisible labels from texts but not from points; building the two lists in different loops; an off-by-one when adding a title label.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/15e912f6f483e096. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs:265

                if (vAlign == VerticalAlignment.Center)
                    dy = -size.Height / 2;

                if (vAlign == VerticalAlignment.Bottom)
                    dy = -size.Height;
            }

            textBlock.RenderTransform = new TranslateTransform(point.X + dx, point.Y + dy);
            textBlock.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled);
        }

        /// <inheritdoc/>
        public void DrawTexts(IList<Point> points, Color color, IList<string> texts, FontFamily fontFamily, double fontSize, FontWeight fontWeight,
            HorizontalAlignment hAlign, VerticalAlignment vAlign, bool isHitTestVisible)
        {
            if (points == null) throw new ArgumentNullException(nameof(points));
            if (texts == null) throw new ArgumentNullException(nameof(texts));

            if (points.Count != texts.Count) throw new ArgumentException($"{nameof(points)} and {nameof(texts)} must have the same number of elements.");

            var brush = GetBrush(color);
            var typeFace = new Typeface(fontFamily, FontStyles.Normal, fontWeight, FontStretches.Normal);

            var visual = new DrawingVisual();
            var context = visual.RenderOpen();
            for (var i = 0; i < points.Count; ++i)
            {
                var text = texts[i];
                var point = points[i];
                var formatted = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, fontSize, brush);
                var dx = 0.0;
                var dy = 0.0;
                if (hAlign != HorizontalAlignment.Left || vAlign != VerticalAlignment.Top)
                {
                    var size = new Size(formatted.Width, formatted.Height);
                    if (hAlign == HorizontalAlignment.Center)
                        dx = -size.Width / 2;

View on GitHub (pinned to 96fad776d2)