{"record":{"id":"7a00668dd7fafeeb","repo":"AvaloniaUI/Avalonia","slug":"invalid-value-value-value-unitstring-for-func","errorCode":null,"errorMessage":"Invalid value {value.Value} {unitString} for {function}","messagePattern":"Invalid value (.+?) (.+?) for (.+?)","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Transformation/TransformParser.cs","lineNumber":356,"sourceCode":"            switch (unit)\n            {\n                case Unit.Radian:\n                case Unit.Gradian:\n                case Unit.Degree:\n                case Unit.Turn:\n                {\n                    return true;\n                }\n            }\n\n            return false;\n        }\n\n        private static void ThrowFormatInvalidValue(TransformFunction function, in UnitValue value)\n        {\n            var unitString = value.Unit == Unit.None ? string.Empty : value.Unit.ToString();\n\n            throw new FormatException($\"Invalid value {value.Value} {unitString} for {function}\");\n        }\n\n        private static void ThrowFormatInvalidValueCount(TransformFunction function, int count)\n        {\n            throw new FormatException($\"Invalid format. {function} expects {count} value(s).\");\n        }\n\n        private static Unit ParseUnit(in ReadOnlySpan<char> part)\n        {\n            foreach (var (name, unit) in s_unitMapping)\n            {\n                if (part.Equals(name.AsSpan(), StringComparison.OrdinalIgnoreCase))\n                {\n                    return unit;\n                }\n            }\n\n            throw new FormatException($\"Invalid unit: {part.ToString()}\");","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Transformation/TransformParser.cs#L338-L374","documentation":"Thrown by TransformParser.ThrowFormatInvalidValue when a value supplied to a transform function has a unit that is not valid for that function. The message includes the numeric value, its unit, and the function name, e.g. 'Invalid value 90 deg for translateX'. Different functions accept different units (pixels for translate, degrees/radians for rotate, etc.).","triggerScenarios":"Passing a value with an incompatible unit to a transform function: e.g. rotate(10px) (rotation expects an angle unit, not pixels), or translate(10deg) (translation expects length/pixels). The validator rejects the combination via ThrowFormatInvalidValue.","commonSituations":"Mixing up angle and length units in hand-written transforms; assuming all functions accept any unit; converting from another CSS engine that is more permissive about units.","solutions":["Match the unit to the function: translate/skew expect length (px), rotate expects angle (deg/grad/rad/turn).","Inspect the '{function}' and '{unitString}' in the message to identify the mismatch.","Convert units before building the string if the source data is in a different unit."],"exampleFix":"// before\nvar t = TransformOperations.Parse(\"rotate(10px)\"); // wrong unit for rotate\n\n// after\nvar t = TransformOperations.Parse(\"rotate(10deg)\");","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return TransformOperations.Parse(s); }\ncatch (FormatException ex) when (ex.Message.Contains(\"Invalid value\"))\n{ /* unit mismatch — convert units and retry */ }","preventionTips":["Use px for translation/skew lengths and deg/rad for rotation angles.","Convert em/%/pt to px before building transform strings.","Inspect the function and unit named in the exception message."],"tags":["transform","parse","format-exception","unit-validation","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}