{"record":{"id":"2bd20237f6121d6d","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-texts","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'texts')","messagePattern":"Value cannot be null\\. \\(Parameter 'texts'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs","lineNumber":263,"sourceCode":"                    dx = -size.Width;\n\n                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);","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs#L245-L281","documentation":"DrawTexts renders a set of strings at given points on the WPF canvas. The library validates that the texts collection is non-null, throwing ArgumentNullException with parameter name 'texts'. Null texts cannot be paired with points for rendering, so the method fails fast.","triggerScenarios":"Calling CanvasRenderer.DrawTexts with a null texts list (IList<string>) while points is valid, e.g. labels loaded from a source that returned null.","commonSituations":"Labels read from config/DB that were null instead of empty; forgetting to initialize the text array; an API returning null when no labels exist.","solutions":["Initialize the texts list before calling DrawTexts, or pass an empty list.","Guard at the call site: if texts is null or empty, skip the call.","Default-deserialize string collections to empty lists."],"exampleFix":"// before\nstring[] texts = LoadLabels(); // may return null\nrenderer.DrawTexts(points, color, texts, font, size, weight, hAlign, vAlign, false);\n// after\nstring[] texts = LoadLabels() ?? Array.Empty<string>();\nif (texts.Length > 0)\n    renderer.DrawTexts(points, color, texts, font, size, weight, hAlign, vAlign, false);","handlingStrategy":"validation","validationCode":"if (texts == null || texts.Count == 0) return; // nothing to draw","typeGuard":"bool hasTexts = texts != null && texts.Count > 0;","tryCatchPattern":"try { renderer.DrawTexts(points, color, texts, ...); } catch (ArgumentNullException ex) when (ex.ParamName == \"texts\") { /* substitute empty list */ }","preventionTips":["Use Array.Empty<T>() / new List<T>() instead of null for 'no items'","Guard label-loading helpers so they never return null","Validate point/text pairing before rendering"],"tags":["csharp","wpf","argument-null"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}