{"record":{"id":"512cf5c08b181f3d","repo":"dotnet/wpf","slug":"sr-transform-notinvertible","errorCode":null,"errorMessage":"SR.Transform_NotInvertible","messagePattern":"SR\\.Transform_NotInvertible","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Media/Matrix.cs","lineNumber":433,"sourceCode":"            {\n                return !DoubleUtil.IsZero(Determinant);\n            }\n        }\n\n        /// <summary>\n        /// Replaces matrix with the inverse of the transformation.  This will throw an InvalidOperationException\n        /// if !HasInverse\n        /// </summary>\n        /// <exception cref=\"InvalidOperationException\">\n        /// This will throw an InvalidOperationException if the matrix is non-invertable\n        /// </exception>\n        public void Invert()\n        {\n            double determinant = Determinant;\n\n            if (DoubleUtil.IsZero(determinant))\n            {\n                throw new System.InvalidOperationException(SR.Transform_NotInvertible);\n            }\n\n            // Inversion does not change the type of a matrix.\n            switch (_type)\n            {\n            case MatrixTypes.TRANSFORM_IS_IDENTITY:\n                break;\n            case MatrixTypes.TRANSFORM_IS_SCALING:\n                {\n                    _m11 = 1.0 / _m11;\n                    _m22 = 1.0 / _m22;\n                }\n                break;\n            case MatrixTypes.TRANSFORM_IS_TRANSLATION:\n                _offsetX = -_offsetX;\n                _offsetY = -_offsetY;\n                break;\n            case MatrixTypes.TRANSFORM_IS_SCALING | MatrixTypes.TRANSFORM_IS_TRANSLATION:","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Media/Matrix.cs#L415-L451","documentation":"Matrix.Invert() throws InvalidOperationException(SR.Transform_NotInvertible) when the matrix determinant is zero (or numerically zero), meaning the matrix is singular and has no inverse. A non-invertible matrix collapses space (e.g. a scale of 0 on an axis), so inversion is mathematically impossible.","triggerScenarios":"Calling Invert() on a matrix with Determinant == 0, e.g. a scale transform with a 0 scale factor, a projection onto a line, or a matrix built from degenerate control points.","commonSituations":"Animating scale to/from 0 and inverting mid-animation; computing inverse transforms for hit-testing with degenerate geometry; user-configurable transforms set to zero-width/height; float round-off producing an exactly-zero determinant.","solutions":["Check Math.Abs(matrix.Determinant) > epsilon before calling Invert().","Guard against zero scale/width/height values feeding into the matrix.","Use Matrix.HasInverse (or TryInvert where available) to test invertibility first.","Catch InvalidOperationException and substitute an identity matrix or skip the inverse operation."],"exampleFix":"// before\nmatrix.Invert(); // throws when singular\n// after\nif (matrix.HasInverse)\n    matrix.Invert();\nelse\n    matrix = Matrix.Identity;","handlingStrategy":"validation","validationCode":"bool invertible = matrix.HasInverse; // or Math.Abs(matrix.Determinant) > 1e-12","typeGuard":"static bool IsInvertible(System.Windows.Media.Matrix m) => m.HasInverse;","tryCatchPattern":"try { matrix.Invert(); }\ncatch (InvalidOperationException) { matrix = Matrix.Identity; }","preventionTips":["Check HasInverse before inverting.","Never allow zero scale factors into transform matrices.","Guard animation/animation keyframes that can pass through zero scale."],"tags":["wpf","matrix","math","singular-matrix"],"backgroundTag":"unsupported-operation","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"}