AvaloniaUI/Avalonia · error · ArgumentNullException

points

Error message

points

What it means

Thrown by the PolyBezierSegment constructor (the overload taking IEnumerable<Point> and isStroked) when the points argument is null. The segment immediately wraps the sequence in a Points collection, which cannot be built from null.

Source

Thrown at src/Avalonia.Base/Media/PolyBezierSegment.cs:31

    /// Points DirectProperty definition
    /// </summary>
    public static readonly DirectProperty<PolyBezierSegment, Points?> PointsProperty =
        AvaloniaProperty.RegisterDirect<PolyBezierSegment, Points?>(nameof(Points),
            o => o.Points,
            (o, v) => o.Points = v);

    private Points? _points = [];

    public PolyBezierSegment()
    {

    }

    public PolyBezierSegment(IEnumerable<Point> points, bool isStroked)
    {
        if (points is null)
        {
            throw new ArgumentNullException(nameof(points));
        }

        Points = new Points(points);
        IsStroked = isStroked;
    }

    /// <summary>
    /// Gets or sets the Point collection that defines this <see cref="PolyBezierSegment"/> object.
    /// </summary>
    /// <value>
    /// The points.
    /// </value>
    [Metadata.Content]
    public Points? Points
    {
        get => _points;
        set => SetAndRaise(PointsProperty, ref _points, value);
    }

View on GitHub (pinned to 11c5427268)

Solutions

  1. Pass a non-null IEnumerable<Point> (e.g. an array or List<Point>); an empty sequence is acceptable.
  2. Use the parameterless constructor and set Points afterward if the collection may be unavailable at construction time.
  3. Null-check the source before constructing the segment.

Example fix

// before
var seg = new PolyBezierSegment(maybeNullPoints, true);

// after
var seg = new PolyBezierSegment(maybeNullPoints ?? Array.Empty<Point>(), true);
Defensive patterns

Strategy: validation

Validate before calling

var pts = points ?? Array.Empty<Point>();
var seg = new PolyBezierSegment(pts, isStroked);

Type guard

static bool HasPoints(IEnumerable<Point>? p) => p is not null;

Prevention

When it happens

Trigger: new PolyBezierSegment(null, isStroked) — passing a null point sequence.

Common situations: Binding or constructing a PolyBezierSegment from a source collection that is null; forgetting to initialize the points list before building the segment.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/49556d7817ee7a34. Report an issue: GitHub.