stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'texts')
Error message
Value cannot be null. (Parameter 'texts')
What it means
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.
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.
Example fix
// before
string[] texts = LoadLabels(); // may return null
renderer.DrawTexts(points, color, texts, font, size, weight, hAlign, vAlign, false);
// after
string[] texts = LoadLabels() ?? Array.Empty<string>();
if (texts.Length > 0)
renderer.DrawTexts(points, color, texts, font, size, weight, hAlign, vAlign, false); Defensive patterns
Strategy: validation
Validate before calling
if (texts == null || texts.Count == 0) return; // nothing to draw
Type guard
bool hasTexts = texts != null && texts.Count > 0;
Try / catch
try { renderer.DrawTexts(points, color, texts, ...); } catch (ArgumentNullException ex) when (ex.ParamName == "texts") { /* substitute empty list */ } Prevention
- 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
When it happens
Trigger: Calling CanvasRenderer.DrawTexts with a null texts list (IList<string>) while points is valid, e.g. labels loaded from a source that returned null.
Common situations: 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.
Related errors
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'property')
- factory
- emitter
- type
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2bd20237f6121d6d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs:263
dx = -size.Width;
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);View on GitHub (pinned to 96fad776d2)