dotnet/maui · error · XamlParseException

Can't resolve {0}

Error message

Can't resolve {0}

What it means

XamlParseException raised by BindablePropertyConverter when converting a single-segment property name (no dot) and the XAML service provider cannot supply IProvideParentValues. Without parent information the converter cannot infer the target Type that owns the property, so it cannot resolve the bare name. Thrown during XAML parsing/compilation, not at runtime binding.

Source

Thrown at src/Controls/src/Core/BindablePropertyConverter.cs:42

		object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider)
		{
			if (string.IsNullOrWhiteSpace(value))
				return null;
			if (serviceProvider == null)
				return null;
			if (!(serviceProvider.GetService(typeof(IXamlTypeResolver)) is IXamlTypeResolver typeResolver))
				return null;
			IXmlLineInfo lineinfo = null;
			if (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider xmlLineInfoProvider)
				lineinfo = xmlLineInfoProvider.XmlLineInfo;
			string[] parts = value.Split('.');
			Type type = null;
			if (parts.Length == 1)
			{
				if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideParentValues parentValuesProvider))
				{
					string msg = string.Format("Can't resolve {0}", parts[0]);
					throw new XamlParseException(msg, lineinfo);
				}
				object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault();
				if (parentValuesProvider.TargetObject is Setter)
				{
					if (parent is Style style)
						type = style.TargetType;
					else if (parent is TriggerBase triggerBase)
						type = triggerBase.TargetType;
					else if (parent is VisualState visualState)
						type = FindTypeForVisualState(parentValuesProvider, lineinfo);
				}
				else if (parentValuesProvider.TargetObject is Trigger)
					type = (parentValuesProvider.TargetObject as Trigger).TargetType;
				else if (parentValuesProvider.TargetObject is PropertyCondition && parent is TriggerBase)
					type = (parent as TriggerBase).TargetType;

				if (type == null)
					throw new XamlParseException($"Can't resolve {parts[0]}", lineinfo);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Prefix the property with its owner type, e.g. Property="VisualElement.BackgroundColor", so the converter does not need parent inference.
  2. If you inflate XAML manually, supply an IProvideValueTarget/IProvideParentValues service in the serviceProvider.
  3. Run the XAML through the compiled XAMLC path in a real MAUI host instead of a bare XamlReader.

Example fix

<!-- before -->
<Setter Property="BackgroundColor" Value="Red" />

<!-- after -->
<Setter Property="VisualElement.BackgroundColor" Value="Red" />
Defensive patterns

Strategy: validation

Validate before calling

// In XAML: always qualify the property when parent services are unavailable.
// <Setter Property="VisualElement.BackgroundColor" Value="Red" />

Try / catch

try { /* XAML load */ }
catch (XamlParseException ex) when (ex.Message.StartsWith("Can't resolve"))
{
    // log and fall back to qualifying the property name manually
}

Prevention

When it happens

Trigger: Authoring a Setter.Property or similar attribute with a bare name (e.g. Property="BackgroundColor") in a context where the XAML loader did not provide IProvideValueTarget/IProvideParentValues; loading XAML via a custom service provider that omits these services; runtime XAML inflation in unit tests without the full MAUI service container.

Common situations: Using XamlReader.Load directly without wiring the MAUI services; third-party XAML hosts that do not implement IProvideParentValues; XAMLC source-generator running on malformed Setter markup.

Related errors


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