dotnet/maui · error · BuildException

XC0040

XC0040

Error message

Cannot convert value "{0}" to "{1}".

What it means

XC0040 Conversion thrown by PointTypeConverter when a XAML string cannot be parsed into a Microsoft.Maui.Graphics.Point. The converter uses Point.TryParse on the trimmed value. If the value is null/empty or Point.TryParse fails (expecting 'x,y' format), the build-time exception fires.

Source

Thrown at src/Controls/src/Build.Tasks/CompiledConverters/PointTypeConverter.cs:23

using Mono.Cecil;
using Mono.Cecil.Cil;

namespace Microsoft.Maui.Controls.XamlC;

class PointTypeConverter : ICompiledTypeConverter
{
	public IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node)
	{
		var module = context.Body.Method.Module;
		if (!string.IsNullOrEmpty(value) && Point.TryParse(value.Trim(), out var point))
		{
			foreach (var instruction in CreatePoint(context, module, point))
			{
				yield return instruction;
			}
			yield break;
		}
		throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Point));
	}

	public IEnumerable<Instruction> CreatePoint(ILContext context, ModuleDefinition module, Point point)
	{
		yield return Instruction.Create(OpCodes.Ldc_R8, point.X);
		yield return Instruction.Create(OpCodes.Ldc_R8, point.Y);
		yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, ("Microsoft.Maui.Graphics", "Microsoft.Maui.Graphics", "Point"), parameterTypes: new[] {
					("mscorlib", "System", "Double"),
					("mscorlib", "System", "Double")}));
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Provide exactly two comma-separated invariant-culture doubles, e.g. '10,20'.
  2. Ensure both coordinates are valid numbers with no extra delimiters or text.
  3. Check for trailing commas, spaces inside numbers, or locale-specific decimal issues.

Example fix

<!-- before -->
<VisualElement.AnchorPoint>10</VisualElement.AnchorPoint>

<!-- after -->
<VisualElement.AnchorPoint>0.5,0.5</VisualElement.AnchorPoint>
Defensive patterns

Strategy: validation

Validate before calling

// Validate a Point XAML string before building
static bool IsValidPoint(string value)
    => !string.IsNullOrWhiteSpace(value)
       && Point.TryParse(value.Trim(), out _);

Prevention

When it happens

Trigger: Setting a Point-typed property (e.g. AnchorX/AnchorY adjacent pairs, or a translation point) to a malformed coordinate string. Point.TryParse expects a comma or space-separated pair of doubles like '10,20' or '10 20'. A single number, three numbers, or non-numeric text fails.

Common situations: Providing only one coordinate instead of two. Using semicolons or other delimiters. Providing a non-numeric value.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/1c4c861acb4f573e. Report an issue: GitHub.