dotnet/wpf · error · ArgumentException

SR.InvalidValueType (formatted with typeof(Matrix))

Error message

SR.InvalidValueType (formatted with typeof(Matrix))

What it means

DrawingAttributes.StylusTipTransform is backed by extended properties that serialize the value as a String, but at runtime it must be a Matrix (or a string parseable to one). This ArgumentException is thrown from property-data validation when the stored value's type is neither. It guards callers against silently receiving an object of the wrong type.

Solutions

  1. Pass a System.Windows.Media.Matrix (or its serialized String form) as the StylusTipTransform property value
  2. Use the DrawingAttributes.StylusTipTransform property instead of raw extended-property APIs for this GUID
  3. Check propertyData.GetType() before assigning custom property data for KnownIds.StylusTipTransform

Example fix

// before
attrs.AddPropertyData(KnownIds.StylusTipTransform, myRotation);
// after
attrs.AddPropertyData(KnownIds.StylusTipTransform, myRotation.ToString(System.Globalization.CultureInfo.InvariantCulture));
Defensive patterns

Strategy: validation

Validate before calling

if (propertyData is string || propertyData is Matrix) { /* ok */ } else { /* reject or convert */ }

Type guard

static bool IsValidStylusTipTransformValue(object v) => v is string || v is System.Windows.Media.Matrix;

Try / catch

try { attrs.AddPropertyData(KnownIds.StylusTipTransform, value); } catch (ArgumentException ex) when (ex.ParamName == nameof(propertyData)) { /* convert value and retry */ }

Prevention

When it happens

Trigger: Passing a propertyData payload for KnownIds.StylusTipTransform whose runtime Type is not String (and not Matrix) — e.g. supplying a raw byte[] or custom object when reading/writing custom property data on DrawingAttributes.

Common situations: Round-tripping ink data between versions or platforms where StylusTipTransform was serialized differently; hand-building ExtendedProperty dictionaries for KnownIds instead of using the StylusTipTransform property.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs:708

            // the Guid is a drawing attribute value
            return null;
        }

        internal static void ValidateStylusTipTransform(Guid propertyDataId, object propertyData)
        {
            // 
            // Calling AddPropertyData(KnownIds.StylusTipTransform, "d") does not throw an ArgumentException.
            //  ExtendedPropertySerializer.Validate take a string as a valid type since StylusTipTransform
            //  gets serialized as a String, but at runtime is a Matrix
            ArgumentNullException.ThrowIfNull(propertyData);

            if (propertyDataId == KnownIds.StylusTipTransform)
            {
                // StylusTipTransform gets serialized as a String, but at runtime is a Matrix
                Type t = propertyData.GetType();
                if (t == typeof(String))
                {
                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(Matrix)), nameof(propertyData));
                }
            }
        }

        /// <summary>
        /// Simple helper method used to determine if a guid
        /// needs to be removed from the ExtendedPropertyCollection in ISF
        /// before serializing
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal static bool RemoveIdFromExtendedProperties(Guid id)
        {
            if (KnownIds.Color == id ||
                KnownIds.Transparency == id ||
                KnownIds.StylusWidth == id ||
                KnownIds.DrawingFlags == id ||
                KnownIds.StylusHeight == id ||

View on GitHub (pinned to 81131a70a4)