{"record":{"id":"23d6cf720063ed65","repo":"dotnet/wpf","slug":"invalidmatrixcontainsinfinity","errorCode":null,"errorMessage":"InvalidMatrixContainsInfinity","messagePattern":"InvalidMatrixContainsInfinity","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":837,"sourceCode":"                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                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(double)), nameof(value));\n                }\n\n                double dVal = (double)value;","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L819-L855","documentation":"Same validation path as NaN: a Matrix-valued StylusTipTransform containing Infinity in any coefficient throws ArgumentException SR.InvalidMatrixContainsInfinity, because infinite values cannot be serialized into ink data.","triggerScenarios":"Assigning a Matrix with infinite coefficients (e.g. from division by a zero determinant when inverting, or unbounded math) to StylusTipTransform, then serializing/validating.","commonSituations":"Inverting a near-singular matrix producing huge/infinite values; zoom math dividing by zero scale; overflow in accumulated transforms.","solutions":["Validate all six coefficients are finite (double.IsInfinity) before assigning","Recompute the transform with guarded division / clamping","Catch ArgumentException and substitute Matrix.Identity"],"exampleFix":"// before\nattrs[KnownIds.StylusTipTransform] = inv; // may contain Infinity\n// after\nif (inv.HasInverse && IsFinite(inv)) attrs[KnownIds.StylusTipTransform] = inv;\nstatic bool IsFinite(Matrix 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));","handlingStrategy":"validation","validationCode":"static bool ContainsInfinity(Matrix 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);\nif (ContainsInfinity(matrix)) matrix = Matrix.Identity;","typeGuard":"static bool IsFinite(Matrix m) => !(double.IsNaN(m.M11)||double.IsInfinity(m.M11)||double.IsNaN(m.M22)||double.IsInfinity(m.M22)||double.IsNaN(m.OffsetX)||double.IsInfinity(m.OffsetX)||double.IsNaN(m.OffsetY)||double.IsInfinity(m.OffsetY));","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Infinity\")) { props[KnownIds.StylusTipTransform] = Matrix.Identity; }","preventionTips":["Never invert a matrix without checking HasInverse first","Clamp computed scale factors to safe ranges","Validate external transform data before use"],"tags":["wpf","ink","matrix","infinity","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"}