dotnet/wpf · error · ArgumentNullException

stylusPointDescription

Error message

stylusPointDescription

What it means

The static StylusPointDescription.AreCompatible throws ArgumentNullException (message 'stylusPointDescription') when either argument is null. Compatibility comparison requires two non-null descriptions since every stylus point stream must have a defined description.

Solutions

  1. Check both arguments for null before calling AreCompatible and skip the comparison (or treat missing description as incompatible) when null.
  2. Ensure the StylusDevice/TabletDevice is available before reading its description.
  3. Use reference equality shortcut: if both are the same instance they are compatible without the call.

Example fix

// before
bool compat = StylusPointDescription.AreCompatible(d1, d2);
// after
bool compat = d1 != null && d2 != null && StylusPointDescription.AreCompatible(d1, d2);
Defensive patterns

Strategy: validation

Validate before calling

if (d1 == null || d2 == null) return false; // or defer until descriptions are available

Type guard

static bool IsNonNull(StylusPointDescription d) => d != null;

Try / catch

try { return StylusPointDescription.AreCompatible(d1, d2); }
catch (ArgumentNullException) { return false; }

Prevention

When it happens

Trigger: Calling StylusPointDescription.AreCompatible(desc1, desc2) where desc1 or desc2 is null, commonly when a device's GetStylusPointDescription returned null or a field/default was never initialized.

Common situations: Comparing descriptions before a TabletDevice/StylusDevice is available (null until device attached); passing a nullable field that defaulted to null in a configuration path.

Related errors


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

Appendix: source

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

        /// <summary>
        /// Internal helper to determine the original pressure index
        /// </summary>
        internal int OriginalPressureIndex
        {
            get { return _originalPressureIndex; }
        }

        /// <summary>
        /// Returns true if the two StylusPointDescriptions have the same StylusPointProperties.  Metrics are ignored.
        /// </summary>
        /// <param name="stylusPointDescription1">stylusPointDescription1</param>
        /// <param name="stylusPointDescription2">stylusPointDescription2</param>
        public static bool AreCompatible(StylusPointDescription stylusPointDescription1, StylusPointDescription stylusPointDescription2)
        {
            if (stylusPointDescription1 == null || stylusPointDescription2 == null)
            {
                throw new ArgumentNullException("stylusPointDescription");
            }

            // if a StylusPointDescription is not null, then _stylusPointPropertyInfos is not null.
            //
            // ignore X, Y, Pressure - they are guaranteed to be the first3 members
            //
            Debug.Assert(   stylusPointDescription1._stylusPointPropertyInfos.Length >= RequiredCountOfProperties &&
                            stylusPointDescription1._stylusPointPropertyInfos[0].Id == StylusPointPropertyIds.X &&
                            stylusPointDescription1._stylusPointPropertyInfos[1].Id == StylusPointPropertyIds.Y &&
                            stylusPointDescription1._stylusPointPropertyInfos[2].Id == StylusPointPropertyIds.NormalPressure);

            Debug.Assert(   stylusPointDescription2._stylusPointPropertyInfos.Length >= RequiredCountOfProperties &&
                            stylusPointDescription2._stylusPointPropertyInfos[0].Id == StylusPointPropertyIds.X &&
                            stylusPointDescription2._stylusPointPropertyInfos[1].Id == StylusPointPropertyIds.Y &&
                            stylusPointDescription2._stylusPointPropertyInfos[2].Id == StylusPointPropertyIds.NormalPressure);

            if (stylusPointDescription1._stylusPointPropertyInfos.Length != stylusPointDescription2._stylusPointPropertyInfos.Length)
            {

View on GitHub (pinned to 81131a70a4)