{"record":{"id":"7a6ddc1282a94822","repo":"AvaloniaUI/Avalonia","slug":"invalid-pixelsize","errorCode":null,"errorMessage":"Invalid PixelSize.","messagePattern":"Invalid PixelSize\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/PixelSize.cs","lineNumber":78,"sourceCode":"        /// <returns>True if the sizes are unequal; otherwise false.</returns>\n        public static bool operator !=(PixelSize left, PixelSize right)\n        {\n            return !(left == right);\n        }\n\n        /// <summary>\n        /// Parses a <see cref=\"PixelSize\"/> string.\n        /// </summary>\n        /// <param name=\"s\">The string.</param>\n        /// <returns>The <see cref=\"PixelSize\"/>.</returns>\n        /// <exception cref=\"FormatException\"/>\n        public static PixelSize Parse(string s)\n        {\n            if (TryParse(s, out var result))\n            {\n                return result;\n            }\n            throw new FormatException(\"Invalid PixelSize.\");\n        }\n\n        /// <summary>\n        /// Try parsing <paramref name=\"source\"/> as <see cref=\"PixelSize\"/>.\n        /// </summary>\n        /// <param name=\"source\">The <see cref=\"string\"/> to parse.</param>\n        /// <param name=\"result\">The result of parsing. if <paramref name=\"source\"/> is not valid <paramref name=\"result\"/> is <see cref=\"PixelSize.Empty\"/> </param>\n        /// <returns><c>true</c> if <paramref name=\"source\"/> is valid <see cref=\"PixelSize\"/>, otherwise <c>false</c>.</returns>\n        public static bool TryParse([NotNullWhen(true)] string? source,\n            out PixelSize result)\n        {\n            result = Empty;\n            if(string.IsNullOrEmpty(source))\n            {\n                return false;\n            }\n            using (var tokenizer = new SpanStringTokenizer(source, exceptionMessage: \"Invalid PixelSize.\"))\n            {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/PixelSize.cs#L60-L96","documentation":"Thrown by PixelSize.Parse when TryParse fails to interpret the input string. PixelSize expects a 'width,height' or 'widthxheight' formatted string of two non-negative integers. If TryParse returns false (malformed, non-numeric, or negative components), Parse wraps the failure in this FormatException.","triggerScenarios":"Calling PixelSize.Parse with a string that is not two non-negative integers in the expected delimiter form, e.g. 'abc', '10', '10x-5', or '10;20'. TryParse returns false and Parse throws.","commonSituations":"Deserializing a size from config/XAML with the wrong delimiter or missing a dimension; user input that omits one component; locale-specific separators (comma vs. period); negative dimensions.","solutions":["Format the string as two non-negative integers separated by a comma, e.g. '1920,1080'.","Prefer PixelSize.TryParse to handle invalid input gracefully without exceptions.","Construct PixelSize directly from ints when the values are available programmatically."],"exampleFix":"// before\nvar size = PixelSize.Parse(\"1920x1080x extra\"); // throws\n\n// after\nvar size = PixelSize.Parse(\"1920,1080\");\n// or safe parse:\nif (PixelSize.TryParse(input, out var size)) { /* use size */ }","handlingStrategy":"validation","validationCode":"static PixelSize SafeParsePixelSize(string s)\n    => PixelSize.TryParse(s, out var size) ? size : PixelSize.Empty;","typeGuard":null,"tryCatchPattern":"try { return PixelSize.Parse(s); }\ncatch (FormatException) { return PixelSize.Empty; }","preventionTips":["Prefer TryParse for user-supplied or external size strings.","Format as two non-negative integers separated by a comma.","Construct PixelSize directly from ints when values are known."],"tags":["pixel-size","parse","format-exception","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}