{"record":{"id":"671e270d02d84472","repo":"dotnet/wpf","slug":"matrixnotinvertible","errorCode":null,"errorMessage":"MatrixNotInvertible","messagePattern":"MatrixNotInvertible","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":829,"sourceCode":"                    throw new ArgumentException(SR.Format(SR.InvalidValueOfType, value, typeof(StylusTip)), nameof(value));\n                }\n            }\n            else if (id == KnownIds.StylusTipTransform)\n            {\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            }","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L811-L847","documentation":"When StylusTipTransform is supplied as a Matrix, ExtendedPropertySerializer requires the matrix to be invertible (it maps the transform back and forth during serialization). A non-invertible matrix (zero determinant) throws ArgumentException with SR.MatrixNotInvertible.","triggerScenarios":"Setting StylusTipTransform to a Matrix whose determinant is 0 — e.g. a matrix that scales an axis to 0 or projects onto a line — then serializing/validating extended properties.","commonSituations":"Building a Matrix from degenerate geometry (ScaleY=0, collapsed layout measurements producing zero scale); interpolating matrices that pass through a singular state.","solutions":["Check Matrix.HasInverse before assigning and skip or substitute Identity when false","Slightly adjust the scale factors so the determinant is non-zero","Catch ArgumentException and fall back to Matrix.Identity"],"exampleFix":"// before\nattrs[KnownIds.StylusTipTransform] = new Matrix(1, 0, 0, 0, 0, 0); // singular\n// after\nMatrix m = new Matrix(1, 0, 0, 1, 0, 0);\nif (m.HasInverse) attrs[KnownIds.StylusTipTransform] = m;","handlingStrategy":"validation","validationCode":"if (!matrix.HasInverse) matrix = Matrix.Identity;","typeGuard":"static bool IsUsableTransform(Matrix m) => m.HasInverse;","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"invertible\") || ex.Message.Contains(\"Matrix\")) { props[KnownIds.StylusTipTransform] = Matrix.Identity; }","preventionTips":["Check Matrix.HasInverse whenever a matrix comes from computation","Avoid constructing matrices with zero scale factors","Clamp interpolated transforms away from singular states"],"tags":["wpf","ink","matrix","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"}