dotnet/maui · error · BuildException
XC0040
XC0040
Error message
Cannot convert value "{0}" to "{1}". What it means
XamlC error XC0040 from ColumnDefinitionCollectionTypeConverter (used by Grid.ColumnDefinitions). The converter only proceeds when the value is non-whitespace; each comma-separated part is then parsed as a GridLength. An empty or whitespace-only value is rejected with XC0040. (A malformed individual part would instead fail inside GridLengthTypeConverter.)
Source
Thrown at src/Controls/src/Build.Tasks/CompiledConverters/ColumnDefinitionCollectionTypeConverter.cs:41
yield return Create(Newarr, module.ImportReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "ColumnDefinition")));
for (var i = 0; i < parts.Length; i++)
{
yield return Create(Dup);
yield return Create(Ldc_I4, i);
foreach (var instruction in gridlengthconverter.ConvertFromString(parts[i], context, node))
yield return instruction;
yield return Create(Newobj, module.ImportCtorReference(context.Cache,
type: ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "ColumnDefinition"),
parameterTypes: new[] { ("Microsoft.Maui", "Microsoft.Maui", "GridLength") }));
yield return Create(Stelem_Ref);
}
yield return Create(Newobj, module.ImportCtorReference(context.Cache,
type: ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "ColumnDefinitionCollection"),
paramCount: 1));
yield break;
}
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(ColumnDefinitionCollection));
}
}
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Provide valid GridLength values separated by commas, e.g. ColumnDefinitions="*,2*,100".
- If no explicit columns are needed, remove the ColumnDefinitions attribute.
Example fix
<!-- before --> <Grid ColumnDefinitions=""> ... </Grid> <!-- after --> <Grid ColumnDefinitions="*,2*"> ... </Grid>
Defensive patterns
Strategy: validation
Prevention
- Provide explicit GridLength values for ColumnDefinitions or omit the attribute.
- Do not leave ColumnDefinitions as an empty string.
- Use GridLength syntax ('*', '1*', '100') consistently across all parts.
When it happens
Trigger: ColumnDefinitions is set to an empty string or whitespace, e.g. ColumnDefinitions="" left in markup.
Common situations: An empty attribute left after editing; a binding/placeholder that produced empty; XAML designer inserting a blank value.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/67c863721c47dff9.
Report an issue: GitHub.