{"record":{"id":"7c9d0c10921a0275","repo":"dotnet/maui","slug":"xc0040-7c9d0c","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/FlexBasisTypeConverter.cs","lineNumber":47,"sourceCode":"\t\t\t\t{\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_R4, (float)(relflex / 100));\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_I4_1); //isRelative: true\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui.Layouts\", \"FlexBasis\"), parameterTypes: new[] {\n\t\t\t\t\t\t(\"mscorlib\", \"System\", \"Single\"),\n\t\t\t\t\t\t(\"mscorlib\", \"System\", \"Boolean\")}));\n\t\t\t\t\tyield break;\n\t\t\t\t}\n\t\t\t\tif (float.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out float flex))\n\t\t\t\t{\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_R4, flex);\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_I4_0); //isRelative: false\n\t\t\t\t\tyield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui.Layouts\", \"FlexBasis\"), parameterTypes: new[] {\n\t\t\t\t\t\t(\"mscorlib\", \"System\", \"Single\"),\n\t\t\t\t\t\t(\"mscorlib\", \"System\", \"Boolean\")}));\n\t\t\t\t\tyield break;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(FlexBasis));\n\t\t}\n\t}\n}\n","sourceCodeStart":29,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/FlexBasisTypeConverter.cs#L29-L51","documentation":"XC0040 Conversion thrown by FlexBasisTypeConverter when a XAML string does not represent a valid Microsoft.Maui.Layouts.FlexBasis. The converter accepts the literal 'Auto', a percentage string like '50%' (parsed as a relative basis), or a plain invariant-culture float. If none of these match, the build exception fires.","triggerScenarios":"Setting FlexLayout.Basis to an unrecognized format such as 'auto ' (trailing issue is fine after trim, but 'Automatic' fails), '0.5px', or a non-numeric word. A plain '100' (absolute) or '50%' (relative) or 'Auto' are the only accepted forms.","commonSituations":"Confusing absolute (unitless number) with percentage — forgetting the '%' suffix. Using CSS-style 'flex-basis' values like '1rem' or '100px'. Misspelling 'Auto' as 'auto' works (case-insensitive for the percent check but 'Auto' is checked with exact equality, so use 'Auto').","solutions":["Use 'Auto' for automatic sizing, a plain number (e.g. '100') for absolute length, or 'NN%' for a percentage of available space.","Ensure percentage values have the '%' suffix and contain a valid float before it.","Remove any unit suffixes other than '%' — pixels, rem, etc. are not supported."],"exampleFix":"<!-- before -->\n<FlexLayout.Basis>50</FlexLayout.Basis>\n\n<!-- after -->\n<FlexLayout.Basis>50%</FlexLayout.Basis>\n<!-- or -->\n<FlexLayout.Basis>Auto</FlexLayout.Basis>","handlingStrategy":"validation","validationCode":"// Validate a FlexBasis XAML string before building\nstatic bool IsValidFlexBasis(string value)\n{\n    if (string.IsNullOrWhiteSpace(value)) return false;\n    value = value.Trim();\n    if (value == \"Auto\") return true;\n    if (value.EndsWith('%') &&\n        float.TryParse(value[..^1], NumberStyles.Number, CultureInfo.InvariantCulture, out _))\n        return true;\n    return float.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out _);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["FlexBasis accepts 'Auto', 'NN%' (relative), or a plain float (absolute) — no other units.","Remember '%' is required for relative sizing; a bare number is always absolute.","Avoid CSS-style units (px, rem, em) — they are not recognized by this converter."],"tags":["xaml","maui","xamlc","type-converter","flexlayout","flexbasis","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}