{"record":{"id":"3654ee08250e05dd","repo":"dotnet/wpf","slug":"sr-invalidvaluetype-formatted-with-typeof-matrix","errorCode":null,"errorMessage":"SR.InvalidValueType (formatted with typeof(Matrix))","messagePattern":"SR\\.InvalidValueType \\(formatted with typeof\\(Matrix\\)\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs","lineNumber":708,"sourceCode":"            // the Guid is a drawing attribute value\n            return null;\n        }\n\n        internal static void ValidateStylusTipTransform(Guid propertyDataId, object propertyData)\n        {\n            // \n            // Calling AddPropertyData(KnownIds.StylusTipTransform, \"d\") does not throw an ArgumentException.\n            //  ExtendedPropertySerializer.Validate take a string as a valid type since StylusTipTransform\n            //  gets serialized as a String, but at runtime is a Matrix\n            ArgumentNullException.ThrowIfNull(propertyData);\n\n            if (propertyDataId == KnownIds.StylusTipTransform)\n            {\n                // StylusTipTransform gets serialized as a String, but at runtime is a Matrix\n                Type t = propertyData.GetType();\n                if (t == typeof(String))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(Matrix)), nameof(propertyData));\n                }\n            }\n        }\n\n        /// <summary>\n        /// Simple helper method used to determine if a guid\n        /// needs to be removed from the ExtendedPropertyCollection in ISF\n        /// before serializing\n        /// </summary>\n        /// <param name=\"id\"></param>\n        /// <returns></returns>\n        internal static bool RemoveIdFromExtendedProperties(Guid id)\n        {\n            if (KnownIds.Color == id ||\n                KnownIds.Transparency == id ||\n                KnownIds.StylusWidth == id ||\n                KnownIds.DrawingFlags == id ||\n                KnownIds.StylusHeight == id ||","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs#L690-L726","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a System.Windows.Media.Matrix (or its serialized String form) as the StylusTipTransform property value","Use the DrawingAttributes.StylusTipTransform property instead of raw extended-property APIs for this GUID","Check propertyData.GetType() before assigning custom property data for KnownIds.StylusTipTransform"],"exampleFix":"// before\nattrs.AddPropertyData(KnownIds.StylusTipTransform, myRotation);\n// after\nattrs.AddPropertyData(KnownIds.StylusTipTransform, myRotation.ToString(System.Globalization.CultureInfo.InvariantCulture));","handlingStrategy":"validation","validationCode":"if (propertyData is string || propertyData is Matrix) { /* ok */ } else { /* reject or convert */ }","typeGuard":"static bool IsValidStylusTipTransformValue(object v) => v is string || v is System.Windows.Media.Matrix;","tryCatchPattern":"try { attrs.AddPropertyData(KnownIds.StylusTipTransform, value); } catch (ArgumentException ex) when (ex.ParamName == nameof(propertyData)) { /* convert value and retry */ }","preventionTips":["Use the typed StylusTipTransform property instead of raw property-data APIs","Serialize Matrix values to invariant-culture strings when using property data","Unit-test ink serialization round-trips for StylusTipTransform"],"tags":["wpf","ink","argumentexception","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}