dotnet/wpf · error · ArgumentException

SR.Stylus_StylusPointsCantBeEmpty

Error message

SR.Stylus_StylusPointsCantBeEmpty

What it means

ArgumentException from RawStylusInput.SetStylusPoints when the replacement StylusPointCollection is empty (after passing the null and description-compatibility checks) — a stylus input report must contain at least one point.

Solutions

  1. Guard before calling: if stylusPoints.Count > 0 then call SetStylusPoints, otherwise skip the call (leave original points intact)
  2. Ensure your filtering logic always retains at least one point or falls back to the original collection

Example fix

// before
rawStylusInput.SetStylusPoints(filtered);
// after
if (filtered.Count > 0)
{
    rawStylusInput.SetStylusPoints(filtered);
}
Defensive patterns

Strategy: validation

Validate before calling

if (points == null || points.Count == 0) return; // skip SetStylusPoints

Try / catch

try { rawStylusInput.SetStylusPoints(points); } catch (ArgumentException ex) when (ex.ParamName == "stylusPoints") { /* keep original points */ }

Prevention

When it happens

Trigger: Calling SetStylusPoints with a StylusPointCollection whose Count is 0 — e.g. after filtering all points out or passing a freshly created empty collection.

Common situations: A StylusPlugIn filters points by some criterion (range, pressure) and every point is filtered out, then the now-empty collection is passed back via SetStylusPoints.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/81783f0956267f2d. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusInput.cs:107

        /// <summary>
        /// Replaces the StylusPoints.
        /// </summary>
        /// <remarks>
        ///     Callers must have Unmanaged code permission to call this API.
        /// </remarks>
        /// <param name="stylusPoints">stylusPoints</param>
        public void SetStylusPoints(StylusPointCollection stylusPoints)
        {
            ArgumentNullException.ThrowIfNull(stylusPoints);

            if (!StylusPointDescription.AreCompatible(  stylusPoints.Description,
                                                        _report.StylusPointDescription))
            {
                throw new ArgumentException(SR.IncompatibleStylusPointDescriptions, nameof(stylusPoints));
            }
            if (stylusPoints.Count == 0)
            {
                throw new ArgumentException(SR.Stylus_StylusPointsCantBeEmpty, nameof(stylusPoints));
            }

            _stylusPoints = stylusPoints.Clone();
        }

        /// <summary>
        /// Returns the RawStylusInputCustomDataList used to notify plugins before  
        /// PreviewStylus event has been processed by application.
        /// </summary>
        public void NotifyWhenProcessed(object callbackData)
        {
            if (_currentNotifyPlugIn == null)
            {
                throw new InvalidOperationException(SR.Stylus_CanOnlyCallForDownMoveOrUp);
            }
            if (_customData == null)
            {
                _customData = new RawStylusInputCustomDataList();

View on GitHub (pinned to 81131a70a4)