{"record":{"id":"49d3eb011526c11c","repo":"dotnet/maui","slug":"xc0040-49d3eb","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/LayoutOptionsConverter.cs","lineNumber":39,"sourceCode":"\t\t\t\tvalue = value.Trim();\n\n\t\t\t\tvar parts = value.Split('.');\n\t\t\t\tif (parts.Length == 1 || (parts.Length == 2 && parts[0] == \"LayoutOptions\"))\n\t\t\t\t{\n\t\t\t\t\tvar options = parts[parts.Length - 1];\n\n\t\t\t\t\tvar fieldReference = module.ImportFieldReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"LayoutOptions\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t fieldName: options,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t isStatic: true);\n\t\t\t\t\tif (fieldReference != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tyield return Instruction.Create(OpCodes.Ldsfld, fieldReference);\n\t\t\t\t\t\tyield break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} while (false);\n\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(LayoutOptions));\n\t\t}\n\t}\n}","sourceCodeStart":21,"sourceCodeEnd":42,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs#L21-L42","documentation":"XC0040 Conversion thrown by LayoutOptionsConverter when a XAML string does not match any public static field on the Microsoft.Maui.Controls.LayoutOptions type. The converter trims the value, optionally accepts a 'LayoutOptions.' prefix, then resolves the remainder as a static field name. If no matching field exists, the build exception fires.","triggerScenarios":"Setting HorizontalOptions or VerticalOptions to an unrecognized value such as 'Middle' (should be 'Center'), 'Justify', 'Stretch' (should be 'Fill'), or a non-static custom alignment. Valid fields: Start, Center, End, Fill, StartAndExpand, CenterAndExpand, EndAndExpand, FillAndExpand, CenterStart, etc.","commonSituations":"Confusing LayoutOptions names with CSS or other framework alignment names. Using deprecated/removed members. Using 'AndExpand' suffix incorrectly. The compiled converter only recognizes fields that actually exist on the LayoutOptions type in the referenced MAUI version.","solutions":["Use one of the valid LayoutOptions static field names: Start, Center, End, Fill, StartAndExpand, CenterAndExpand, EndAndExpand, or FillAndExpand.","The 'LayoutOptions.' prefix is optional — 'Center' and 'LayoutOptions.Center' are equivalent.","Verify the field exists in your MAUI version — some newer layout options may have different names."],"exampleFix":"<!-- before -->\n<Label HorizontalOptions=\"Middle\" />\n\n<!-- after -->\n<Label HorizontalOptions=\"Center\" />","handlingStrategy":"validation","validationCode":"// Validate a LayoutOptions XAML string against known static fields\nstatic readonly HashSet<string> ValidLayoutOptions = new(StringComparer.OrdinalIgnoreCase)\n{\n    \"Start\",\"Center\",\"End\",\"Fill\",\n    \"StartAndExpand\",\"CenterAndExpand\",\"EndAndExpand\",\"FillAndExpand\"\n};\nstatic bool IsValidLayoutOptions(string value)\n{\n    if (string.IsNullOrWhiteSpace(value)) return false;\n    var name = value.Trim();\n    if (name.StartsWith(\"LayoutOptions.\", StringComparison.OrdinalIgnoreCase))\n        name = name[\"LayoutOptions.\".Length..];\n    return ValidLayoutOptions.Contains(name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'Center' not 'Middle', and 'Fill' not 'Stretch' — these are the most common mistakes.","The 'LayoutOptions.' prefix is optional.","Check the MAUI version's LayoutOptions type for all available static fields."],"tags":["xaml","maui","xamlc","type-converter","layoutoptions","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}