dotnet/wpf · error · ArgumentException

SR.InvalidStylusPointDescriptionDuplicatesFound

Error message

SR.InvalidStylusPointDescriptionDuplicatesFound

What it means

The StylusPointDescription constructor rejects duplicate property IDs beyond the required X/Y/pressure trio. Each StylusPointProperty Guid must appear at most once, because properties are stored in a flat array and looked up by ID; duplicates would make indexing ambiguous. This ArgumentException names stylusPointPropertyInfos as the offending parameter.

Solutions

  1. De-duplicate the collection before constructing, e.g. filter with a HashSet<Guid> on each info's Id.
  2. Check that button property Guids (e.g. StylusPointPropertyIds.TipButton, BarrelButton) are each added only once.
  3. When merging descriptions, use StylusPointDescription.GetStylusPointProperties() and Distinct() by Id.

Example fix

// before
var desc = new StylusPointDescription(new[]{ infoX, infoY, infoPressure, tipButton, tipButton });
// after
var seen = new HashSet<Guid>();
var unique = allInfos.Where(i => seen.Add(i.Id)).ToArray();
var desc = new StylusPointDescription(unique);
Defensive patterns

Strategy: validation

Validate before calling

var seen = new HashSet<Guid>();
bool hasDuplicates = infos.Any(i => !seen.Add(i.Id));

Try / catch

try { var desc = new StylusPointDescription(infos); }
catch (ArgumentException) { infos = infos.GroupBy(i => i.Id).Select(g => g.First()).ToArray(); desc = new StylusPointDescription(infos); }

Prevention

When it happens

Trigger: Calling new StylusPointDescription(stylusPointPropertyInfos) where any of infos[3..] repeats a Guid that was already seen (or repeats X/Y/pressure IDs).

Common situations: Merging two device description lists and appending a property that is already present; adding a button property whose Guid equals an existing property Guid; generating infos in a loop that adds the same custom property per data field.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

                infos[RequiredPressureIndex].Id != StylusPointPropertyIds.NormalPressure)
            {
                throw new ArgumentException(SR.InvalidStylusPointDescription, nameof(stylusPointPropertyInfos));
            }

            //
            // look for duplicates, validate that buttons are last
            //
            List<Guid> seenIds = new List<Guid>();
            seenIds.Add(StylusPointPropertyIds.X);
            seenIds.Add(StylusPointPropertyIds.Y);
            seenIds.Add(StylusPointPropertyIds.NormalPressure);

            int buttonCount = 0;
            for (int x = RequiredCountOfProperties; x < infos.Count; x++)
            {
                if (seenIds.Contains(infos[x].Id))
                {
                    throw new ArgumentException(SR.InvalidStylusPointDescriptionDuplicatesFound, nameof(stylusPointPropertyInfos));
                }
                if (infos[x].IsButton)
                {
                    buttonCount++;
                }
                else
                {
                    //this is not a button, make sure we haven't seen one before
                    if (buttonCount > 0)
                    {
                        throw new ArgumentException(SR.InvalidStylusPointDescriptionButtonsMustBeLast, nameof(stylusPointPropertyInfos));
                    }
                }
                seenIds.Add(infos[x].Id);
            }
            if (buttonCount > MaximumButtonCount)
            {
                throw new ArgumentException(SR.InvalidStylusPointDescriptionTooManyButtons, nameof(stylusPointPropertyInfos));

View on GitHub (pinned to 81131a70a4)