{"record":{"id":"f1f3c8cb933b9990","repo":"AvaloniaUI/Avalonia","slug":"invalid-transform-string-s","errorCode":null,"errorMessage":"Invalid transform string: '{s}'.","messagePattern":"Invalid transform string: '(.+?)'\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Transformation/TransformParser.cs","lineNumber":37,"sourceCode":"            (\"skewY\", TransformFunction.SkewY),\n            (\"rotate\", TransformFunction.Rotate),\n            (\"matrix\", TransformFunction.Matrix)\n        };\n\n        private static readonly (string, Unit)[] s_unitMapping =\n        {\n            (\"deg\", Unit.Degree),\n            (\"grad\", Unit.Gradian),\n            (\"rad\", Unit.Radian),\n            (\"turn\", Unit.Turn), \n            (\"px\", Unit.Pixel)\n        };\n\n        public static TransformOperations Parse(string s)\n        {\n            void ThrowInvalidFormat()\n            {\n                throw new FormatException($\"Invalid transform string: '{s}'.\");\n            }\n\n            if (string.IsNullOrEmpty(s))\n            {\n                throw new ArgumentException(nameof(s));\n            }\n\n            var span = s.AsSpan().Trim();\n\n            if (span.Equals(\"none\".AsSpan(), StringComparison.OrdinalIgnoreCase))\n            {\n                return TransformOperations.Identity;\n            }\n\n            var builder = TransformOperations.CreateBuilder(0);\n\n            while (true)\n            {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Transformation/TransformParser.cs#L19-L55","documentation":"Thrown by TransformParser.Parse (via its local ThrowInvalidFormat function) when the transform string cannot be interpreted as a valid CSS-style transform. After early null/empty and 'none' checks, the parser tokenizes the string into transform functions (e.g. translate, rotate, scale) with their arguments; if the structure is malformed it raises this FormatException. The message echoes the offending input string.","triggerScenarios":"Calling TransformOperations.Parse with a malformed transform expression — e.g. an unknown function name, mismatched parentheses, missing arguments, or a stray token the tokenizer cannot classify. The error originates inside the local ThrowInvalidFormat closure invoked from the main parse loop.","commonSituations":"Loading a transform from CSS/XAML/markup authored by hand with syntax errors; copy-pasting a WPF or browser transform that uses a function Avalonia does not support; concatenating transform fragments dynamically and producing malformed output; version differences where a transform function name changed.","solutions":["Validate the transform string syntax against the supported function set (translate, translateX/Y, rotate, scale, skew, matrix, etc.) before parsing.","Use TransformOperations builder APIs instead of string parsing when constructing transforms programmatically.","Inspect the echoed '{s}' value in the message to locate the exact malformed token."],"exampleFix":"// before\nvar t = TransformOperations.Parse(\"transalte(10px,20px)\"); // typo, throws\n\n// after\nvar t = TransformOperations.Parse(\"translate(10px, 20px)\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return TransformOperations.Parse(s); }\ncatch (FormatException ex) { log.Error($\"Bad transform '{s}'\", ex); return TransformOperations.Identity; }","preventionTips":["Prefer the TransformOperations builder API over string parsing for programmatic transforms.","Validate transform syntax against the supported function set before parsing.","Treat user-supplied transform strings as untrusted input."],"tags":["transform","parse","format-exception","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}