{"record":{"id":"37a7defd2b40e64c","repo":"dotnet/maui","slug":"xc0040-37a7de","errorCode":"XC0040","errorMessage":"Cannot convert value \"{0}\" to \"{1}\".","messagePattern":"Cannot convert value \"(.+?)\" to \"(.+?)\"\\.","errorType":"error_code","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledConverters/GridLengthTypeConverter.cs","lineNumber":52,"sourceCode":"\t\t\t\t\tyield return Create(Ldc_R8, length);\n\t\t\t\t\tyield return Create(Ldc_I4, (int)GridUnitType.Star);\n\t\t\t\t\tyield return Create(Newobj, module.ImportCtorReference(context.Cache,\n\t\t\t\t\t\t\ttype: module.GetTypeDefinition(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui\", \"GridLength\")),\n\t\t\t\t\t\t\tparameterTypes: new[] { module.TypeSystem.Double, module.GetTypeDefinition(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui\", \"GridUnitType\")) }));\n\t\t\t\t\tyield break;\n\t\t\t\t}\n\t\t\t\tif (double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out length))\n\t\t\t\t{\n\t\t\t\t\tyield return Create(Ldc_R8, length);\n\t\t\t\t\tyield return Create(Newobj, module.ImportCtorReference(context.Cache,\n\t\t\t\t\t\t\ttype: module.GetTypeDefinition(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui\", \"GridLength\")),\n\t\t\t\t\t\t\tparameterTypes: new[] { module.TypeSystem.Double }));\n\t\t\t\t\tyield break;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(GridLength));\n\t\t}\n\t}\n}\n","sourceCodeStart":34,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/GridLengthTypeConverter.cs#L34-L56","documentation":"XC0040 Conversion thrown by GridLengthTypeConverter when a XAML string is not a valid Microsoft.Maui.GridLength. Accepted forms are: 'auto'/'Auto' (case-insensitive), '*' (one star), 'N*' (N stars with a numeric multiplier), or a plain invariant-culture double (absolute pixels). If the value is null/whitespace or none of these patterns match, the build exception fires.","triggerScenarios":"Setting a Grid row/column definition to an invalid format such as 'star', '2x', 'auto ', '100px', or a non-numeric word. Valid examples: 'auto', '*', '2*', '100'.","commonSituations":"Misspelling 'auto' (e.g. 'Auto' works but 'autom' does not). Using '2x' instead of '2*'. Adding 'px' or other unit suffixes. An empty value in a RowDefinitions/ColumnDefinitions string.","solutions":["Use 'Auto' for auto-sized rows/columns, '*' for proportional (star) sizing, 'N*' for weighted proportional, or a plain number for absolute pixels.","Check for trailing characters, stray unit suffixes, or typos in 'auto' and '*'.","For star sizing, ensure the numeric prefix before '*' is a valid invariant-culture double."],"exampleFix":"<!-- before -->\n<RowDefinitions>100px,2x,auto</RowDefinitions>\n\n<!-- after -->\n<RowDefinitions>100,2*,Auto</RowDefinitions>","handlingStrategy":"validation","validationCode":"// Validate a GridLength XAML string before building\nstatic bool IsValidGridLength(string value)\n{\n    if (string.IsNullOrWhiteSpace(value)) return false;\n    value = value.Trim();\n    if (value.Equals(\"auto\", StringComparison.OrdinalIgnoreCase)) return true;\n    if (value == \"*\") return true;\n    if (value.EndsWith('*') &&\n        double.TryParse(value[..^1], NumberStyles.Number, CultureInfo.InvariantCulture, out _))\n        return true;\n    return double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out _);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["GridLength syntax: 'Auto', '*', 'N*' (star with multiplier), or a plain number (absolute).","Use '2*' not '2x' for weighted proportional sizing.","No unit suffixes are accepted — bare numbers or the '*' suffix only."],"tags":["xaml","maui","xamlc","type-converter","gridlength","grid","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}