{"record":{"id":"95ca1282d4948cdf","repo":"dotnet/maui","slug":"xc0040-95ca12","errorCode":"XC0040","errorMessage":"Cannot convert value \"{0}\" to \"{1}\".","messagePattern":"Cannot convert value \"(.+?)\" to \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs","lineNumber":41,"sourceCode":"\t\t\t\t\tcase 1:\n\t\t\t\t\t\tif (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l))\n\t\t\t\t\t\t\treturn GenerateIL(context, module, l);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\tif (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&\n\t\t\t\t\t\t\tdouble.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t))\n\t\t\t\t\t\t\treturn GenerateIL(context, module, l, t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 4:\n\t\t\t\t\t\tif (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&\n\t\t\t\t\t\t\tdouble.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t) &&\n\t\t\t\t\t\t\tdouble.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out r) &&\n\t\t\t\t\t\t\tdouble.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out b))\n\t\t\t\t\t\t\treturn GenerateIL(context, module, l, t, r, b);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Thickness));\n\t\t}\n\n\t\tIEnumerable<Instruction> GenerateIL(ILContext context, ModuleDefinition module, params double[] args)\n\t\t{\n\t\t\tforeach (var d in args)\n\t\t\t\tyield return Instruction.Create(OpCodes.Ldc_R8, d);\n\t\t\tyield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, (\"Microsoft.Maui\", \"Microsoft.Maui\", \"Thickness\"), parameterTypes: args.Select(a => (\"mscorlib\", \"System\", \"Double\")).ToArray()));\n\t\t}\n\t}\n\n}","sourceCodeStart":23,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs#L23-L52","documentation":"XC0040 Conversion thrown by ThicknessTypeConverter when a XAML string cannot be parsed into a Microsoft.Maui.Thickness. The converter splits on commas and accepts 1 value (uniform), 2 values (horizontal, vertical), or 4 values (left, top, right, bottom). If the count is not 1, 2, or 4, or any segment fails double.TryParse, the build exception fires.","triggerScenarios":"Setting Margin, Padding, or another Thickness property to 3 comma-separated values (unsupported), a non-numeric segment, or empty. Examples: '10,20,30' (3 values — Thickness does not support 3), '10px,20px' (unit suffixes), '1,2,3,4,5' (5 values).","commonSituations":"Providing 3 values ( Thickness supports only 1, 2, or 4). Using unit suffixes like 'px'. Mixing up the order (Thickness order is left, top, right, bottom, not top/right/bottom/left).","solutions":["Use 1 value (uniform), 2 values (horizontal, vertical), or 4 values (left, top, right, bottom), comma-separated.","Remove any unit suffixes — values must be bare invariant-culture doubles.","For 3-sided padding, use 4 values with 0 for the side you want to be zero (e.g. '10,0,10,0' for left/right only)."],"exampleFix":"<!-- before -->\n<Label Margin=\"10,20,30\" />\n\n<!-- after -->\n<Label Margin=\"10,20,30,40\" />","handlingStrategy":"validation","validationCode":"// Validate a Thickness XAML string (1, 2, or 4 doubles) before building\nstatic bool IsValidThickness(string value)\n{\n    if (string.IsNullOrEmpty(value)) return false;\n    var parts = value.Split(',');\n    if (parts.Length != 1 && parts.Length != 2 && parts.Length != 4) return false;\n    return parts.All(p => double.TryParse(p.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture, out _));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Thickness accepts 1 (uniform), 2 (horizontal, vertical), or 4 (left, top, right, bottom) values — never 3. Providing 3 values is the most common mistake.","No unit suffixes — use bare numbers.","Remember the 4-value order is left, top, right, bottom (not top, right, bottom, left)."],"tags":["xaml","maui","xamlc","type-converter","thickness","margin","padding","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}