dotnet/maui · error · BuildException
XC0040
XC0040
Error message
Cannot convert value "{0}" to "{1}". What it means
XamlC error XC0040 from BoundsTypeConverter (used by AbsoluteLayout.LayoutBounds). An empty or null value is rejected immediately because a Bounds/Rect requires at least an x,y pair.
Source
Thrown at src/Controls/src/Build.Tasks/CompiledConverters/BoundsTypeConverter.cs:19
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.Maui.Controls.Build.Tasks;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Microsoft.Maui.Controls.XamlC
{
class BoundsTypeConverter : ICompiledTypeConverter
{
public IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
{
var module = context.Body.Method.Module;
if (string.IsNullOrEmpty(value))
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Rect));
double x = -1, y = -1, w = -1, h = -1;
bool hasX, hasY, hasW, hasH;
var xywh = value.Split(',');
if (xywh.Length != 2 && xywh.Length != 4)
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Rect));
hasX = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x);
hasY = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y);
hasW = xywh.Length == 4 && double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out w);
hasH = xywh.Length == 4 && double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out h);
if (!hasW && xywh.Length == 4 && string.Compare("AutoSize", xywh[2].Trim(), StringComparison.OrdinalIgnoreCase) == 0)
{
hasW = true;
w = AbsoluteLayout.AutoSize;
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Provide a valid bounds value such as '0,0' or '0,0,100,50'.
- If no explicit bounds are needed, remove the LayoutBounds attribute entirely.
Example fix
<!-- before --> <BoxView LayoutBounds="" /> <!-- after --> <BoxView LayoutBounds="0,0,100,50" />
Defensive patterns
Strategy: validation
Prevention
- Never leave LayoutBounds empty; either set 'x,y' / 'x,y,w,h' or remove the attribute.
- Run the XAML compiler (XamlC) in build so empty-value errors surface at compile time.
- Avoid editor placeholders that resolve to empty strings.
When it happens
Trigger: LayoutBounds is set to an empty string or whitespace, e.g. LayoutBounds="" left over in markup.
Common situations: An empty attribute left in XAML after editing; a binding/placeholder that resolved to empty; tooling inserting a blank value.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/616523ee474ef669.
Report an issue: GitHub.