{"record":{"id":"18081bc6c9d94e9a","repo":"dotnet/wpf","slug":"invalidmatrixcontainsnan","errorCode":null,"errorMessage":"InvalidMatrixContainsNaN","messagePattern":"InvalidMatrixContainsNaN","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":833,"sourceCode":"            {\n                //\n                // StylusTipTransform gets serialized as a String, but at runtime is a Matrix\n                //\n                Type t = value.GetType();\n                if ( t != typeof(String) && t != typeof(Matrix) )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType1, typeof(String), typeof(Matrix)), nameof(value));\n                }\n                else if ( t == typeof(Matrix) )\n                {\n                    Matrix matrix = (Matrix)value;\n                    if ( !matrix.HasInverse )\n                    {\n                        throw new ArgumentException(SR.MatrixNotInvertible, nameof(value));\n                    }\n                    if ( MatrixHelper.ContainsNaN(matrix))\n                    {\n                        throw new ArgumentException(SR.InvalidMatrixContainsNaN, nameof(value));\n                    }\n                    if ( MatrixHelper.ContainsInfinity(matrix))\n                    {\n                        throw new ArgumentException(SR.InvalidMatrixContainsInfinity, nameof(value));\n                    }\n}\n            }\n            else if (id == KnownIds.IsHighlighter)\n            {\n                if ( value.GetType() != typeof(bool))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(bool)), nameof(value));\n                }\n            }\n            else if ( id == KnownIds.StylusHeight || id == KnownIds.StylusWidth )\n            {\n                if ( value.GetType() != typeof(double) )\n                {","sourceCodeStart":815,"sourceCodeEnd":851,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L815-L851","documentation":"Validation error in the ink (ISF) custom-attribute serializer when the value stored for StylusTipTransform is neither a String nor a Matrix, or the Matrix is invalid (e.g. contains NaN / has no inverse); the sentinel names the failing shape check during serialization of StylusTipTransform.","triggerScenarios":"Assigning a Matrix with NaN in any of its six coefficients (from uninitialized doubles, 0.0/0.0 computations, or NaN origin offsets) to StylusTipTransform and serializing.","commonSituations":"Matrix built from NaN layout results or division by zero in transform math; data read from corrupt external sources.","solutions":["Check MatrixHelper-style NaN before assigning (compare coefficients via Matrix decodes / double.IsNaN on components)","Recompute the matrix from valid source values","Catch ArgumentException and reset the property to Matrix.Identity"],"exampleFix":"// before\nattrs[KnownIds.StylusTipTransform] = computedMatrix;\n// after\nif (!HasNaN(computedMatrix)) attrs[KnownIds.StylusTipTransform] = computedMatrix;\nstatic bool HasNaN(Matrix m) => double.IsNaN(m.M11) || double.IsNaN(m.M12) || double.IsNaN(m.M21) || double.IsNaN(m.M22) || double.IsNaN(m.OffsetX) || double.IsNaN(m.OffsetY);","handlingStrategy":"validation","validationCode":"static bool ContainsNaN(Matrix m) => double.IsNaN(m.M11)||double.IsNaN(m.M12)||double.IsNaN(m.M21)||double.IsNaN(m.M22)||double.IsNaN(m.OffsetX)||double.IsNaN(m.OffsetY);\nif (ContainsNaN(matrix)) matrix = Matrix.Identity;","typeGuard":"static bool IsFinite(Matrix m) => !(ContainsNaN(m) || double.IsInfinity(m.M11)||double.IsInfinity(m.M12)||double.IsInfinity(m.M21)||double.IsInfinity(m.M22)||double.IsInfinity(m.OffsetX)||double.IsInfinity(m.OffsetY));","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"NaN\")) { props[KnownIds.StylusTipTransform] = Matrix.Identity; }","preventionTips":["Guard every division used in transform math","Check source geometry for NaN before building matrices","Add NaN asserts in debug builds when composing transforms"],"tags":["wpf","ink","matrix","nan","argumentexception"],"backgroundTag":"invalid-argument-value","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"}