{"record":{"id":"15e912f6f483e096","repo":"stride3d/stride","slug":"points-and-texts-must-have-the-same-number-of-elements","errorCode":null,"errorMessage":"points and texts must have the same number of elements.","messagePattern":"points and texts must have the same number of elements\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs","lineNumber":265,"sourceCode":"                if (vAlign == VerticalAlignment.Center)\n                    dy = -size.Height / 2;\n\n                if (vAlign == VerticalAlignment.Bottom)\n                    dy = -size.Height;\n            }\n\n            textBlock.RenderTransform = new TranslateTransform(point.X + dx, point.Y + dy);\n            textBlock.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled);\n        }\n\n        /// <inheritdoc/>\n        public void DrawTexts(IList<Point> points, Color color, IList<string> texts, FontFamily fontFamily, double fontSize, FontWeight fontWeight,\n            HorizontalAlignment hAlign, VerticalAlignment vAlign, bool isHitTestVisible)\n        {\n            if (points == null) throw new ArgumentNullException(nameof(points));\n            if (texts == null) throw new ArgumentNullException(nameof(texts));\n\n            if (points.Count != texts.Count) throw new ArgumentException($\"{nameof(points)} and {nameof(texts)} must have the same number of elements.\");\n\n            var brush = GetBrush(color);\n            var typeFace = new Typeface(fontFamily, FontStyles.Normal, fontWeight, FontStretches.Normal);\n\n            var visual = new DrawingVisual();\n            var context = visual.RenderOpen();\n            for (var i = 0; i < points.Count; ++i)\n            {\n                var text = texts[i];\n                var point = points[i];\n                var formatted = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeFace, fontSize, brush);\n                var dx = 0.0;\n                var dy = 0.0;\n                if (hAlign != HorizontalAlignment.Left || vAlign != VerticalAlignment.Top)\n                {\n                    var size = new Size(formatted.Width, formatted.Height);\n                    if (hAlign == HorizontalAlignment.Center)\n                        dx = -size.Width / 2;","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs#L247-L283","documentation":"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.","triggerScenarios":"Calling DrawTexts where points.Count != texts.Count, e.g. filtering labels after computing points, or appending items to one list but not the other.","commonSituations":"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.","solutions":["Rebuild both lists in the same loop so they always stay the same length.","Assert/verify points.Count == texts.Count before the call.","If some points have no label, pad texts with empty strings instead of omitting entries."],"exampleFix":"// before\nvar texts = labels.Where(l => l.Visible).ToList(); // filtered, points not filtered\nrenderer.DrawTexts(points, color, texts, ...);\n// after\nvar texts = points.Select((p, i) => labels[i].Visible ? labels[i].Text : \"\").ToList();\nrenderer.DrawTexts(points, color, texts, ...);","handlingStrategy":"validation","validationCode":"if (points == null || texts == null || points.Count != texts.Count) throw new ArgumentException(\"points and texts must be the same length\");","typeGuard":null,"tryCatchPattern":"try { renderer.DrawTexts(points, color, texts, ...); } catch (ArgumentException ex) { /* rebuild lists together, log mismatch */ }","preventionTips":["Build points and texts in the same loop","Pad missing labels with empty strings rather than omitting entries","Add a debug assert comparing counts before draw calls"],"tags":["csharp","wpf","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}