dotnet/wpf · error · ArgumentException

SR.IncompatibleStylusPointDescriptions

Error message

SR.IncompatibleStylusPointDescriptions

What it means

StylusPointCollection.Add(IEnumerable<StylusPoint>) throws ArgumentException when the incoming points' StylusPointDescription is not compatible with the collection's existing description. All points in one collection must share a compatible packet description (property set), enforced via StylusPointDescription.AreCompatible.

Solutions

  1. Reformat the points first: use sourceCollection.Reformat(targetDescription, transform) to convert them
  2. Verify compatibility before adding with StylusPointDescription.AreCompatible(points.Description, target.Description)
  3. Create the target collection from the same description as the points being added

Example fix

// before
targetStroke.StylusPoints.Add(sourceStroke.StylusPoints);
// after
var reformatted = sourceStroke.StylusPoints.Reformat(targetStroke.StylusPoints.Description, null);
targetStroke.StylusPoints.Add(reformatted);
Defensive patterns

Strategy: validation

Validate before calling

if (!StylusPointDescription.AreCompatible(source.Description, target.Description))
    source = source.Reformat(target.Description, null);
target.Add(source);

Type guard

bool CanAdd(StylusPointCollection target, StylusPointCollection src) => StylusPointDescription.AreCompatible(src.Description, target.Description);

Try / catch

try { target.Add(sourcePoints); } catch (ArgumentException ex) when (ex.ParamName == "stylusPoints") { target.Add(sourcePoints.Reformat(target.Description, null)); }

Prevention

When it happens

Trigger: Calling spc.Add(pointsFromAnotherCollectionOrDevice) whose Description has different/incompatible StylusPointProperties than the target collection (e.g. points from a different digitizer or created with a custom description).

Common situations: Merging strokes captured from two different tablet devices; copying points between collections built with different GetStylusDescriptions; mixing real device points with synthetically constructed points (default description).

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

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

                }

                //this does not go through our protected virtuals
                ((List<StylusPoint>)this.Items).Add(newPoint);
            }
        }

        /// <summary>
        /// Adds the StylusPoints in the StylusPointCollection to this StylusPointCollection
        /// </summary>
        /// <param name="stylusPoints">stylusPoints</param>
        public void Add(StylusPointCollection stylusPoints)
        {
            //note that we don't raise an exception if stylusPoints.Count == 0
            ArgumentNullException.ThrowIfNull(stylusPoints);
            if (!StylusPointDescription.AreCompatible(stylusPoints.Description,
                                                        _stylusPointDescription))
            {
                throw new ArgumentException(SR.IncompatibleStylusPointDescriptions, nameof(stylusPoints));
            }

            // cache count outside of the loop, so if this SPC is ever passed
            // we don't loop forever
            int count = stylusPoints.Count;
            for (int x = 0; x < count; x++)
            {
                StylusPoint stylusPoint = stylusPoints[x];
                stylusPoint.Description = _stylusPointDescription;
                //this does not go through our protected virtuals
                ((List<StylusPoint>)this.Items).Add(stylusPoint);
            }

            if (stylusPoints.Count > 0)
            {
                OnChanged(EventArgs.Empty);
            }
        }

View on GitHub (pinned to 81131a70a4)