dotnet/maui · error · BuildException

XC0040

XC0040

Error message

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

What it means

XamlC error XC0040 from BrushTypeConverter. The compiled brush converter accepts either a '#'-prefixed hex color (converted to a SolidColorBrush) or the name of a static property on the Brush type (e.g. a named brush). Anything else, including an empty value or an unrecognized name, throws XC0040.

Source

Thrown at src/Controls/src/Build.Tasks/CompiledConverters/BrushTypeConverter.cs:43

				yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "SolidColorBrush"), parameterTypes: new[] {
						("Microsoft.Maui.Graphics", "Microsoft.Maui.Graphics", "Color")}));

				yield break;
			}

			var propertyGetterReference = module.ImportPropertyGetterReference(context.Cache,
																				("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "Brush"),
																				value,
																				isStatic: true,
																				caseSensitive: false);

			if (propertyGetterReference != null)
			{
				yield return Instruction.Create(OpCodes.Call, propertyGetterReference);
				yield break;
			}
		}
		throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Brush));
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use '#'-prefixed hex for a solid color, e.g. Background="#3498DB".
  2. Use a valid named static Brush property if you need a predefined brush.
  3. If you only need a color, ensure the target expects a Brush and prefix hex with '#'.

Example fix

<!-- before -->
<Frame Background="CornflowerBlue" />
<!-- 'CornflowerBlue' is a Color name, not a Brush property -->

<!-- after -->
<Frame Background="#FF6495ED" />
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: A Brush-typed attribute is set to a value that is neither '#RRGGBB' hex nor a recognized static Brush property — e.g. a bare color name without '#', a typo, or an empty string.

Common situations: Using a color name where a brush is expected without the '#' prefix; misspelling a named brush; assuming an HTML/CSS gradient string is supported.

Related errors


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