dotnet/maui · error · XamlParseException
Can't resolve {parts[0]}
Error message
Can't resolve {parts[0]} What it means
XamlParseException raised after the converter walked the parent chain for a single-segment property name but could not determine an owning Type. It tried Setter/Style, TriggerBase, VisualState, Trigger, and PropertyCondition branches; none matched, so type stayed null and the converter refuses to guess which BindableProperty the bare name refers to.
Source
Thrown at src/Controls/src/Core/BindablePropertyConverter.cs:60
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);
return ConvertFrom(type, parts[0], lineinfo);
}
if (parts.Length == 2)
{
if (!typeResolver.TryResolve(parts[0], out type))
{
string msg = string.Format("Can't resolve {0}", parts[0]);
throw new XamlParseException(msg, lineinfo);
}
return ConvertFrom(type, parts[1], lineinfo);
}
throw new XamlParseException($"Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyName.", lineinfo);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var strValue = value?.ToString();View on GitHub (pinned to f377ff1c5e)
Solutions
- Qualify the property with its owner type: Property="VisualElement.BackgroundColor".
- Move the Setter into a recognized parent (Style, Trigger, or VisualStateGroup/VisualState chain).
- If the parent is a custom TriggerBase, ensure it exposes TargetType so the converter can read it.
Example fix
<!-- before --> <Setter Property="BackgroundColor" Value="Red" /> <!-- after --> <Setter Property="VisualElement.BackgroundColor" Value="Red" />
Defensive patterns
Strategy: validation
Validate before calling
// Prefer qualified property names in Setters that may sit in non-standard parents: // Property="VisualElement.BackgroundColor"
Try / catch
try { /* compile XAML */ }
catch (XamlParseException ex) when (ex.Message.Contains("Can't resolve"))
{
// instruct the author to qualify the property name
} Prevention
- Always qualify bare property names with the owning type in Setters.
- Keep Setter inside recognized parents (Style/Trigger/VisualState).
When it happens
Trigger: A bare property name inside an element whose parent chain is not one of the recognized shapes (Setter in Style/Trigger/VisualState). For example a Setter nested in an unsupported container, or a custom markup that places Setter somewhere the converter does not look.
Common situations: Hand-authored or tool-generated XAML that nests Setter/Trigger in unusual parents; custom TriggerBase subclasses; XAML written for an older API surface that has since changed parent expectations.
Related errors
- Can't resolve {name} on {type.Name}
- Can't resolve {0}
- Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyNam
- The PropertyName of {type.Name}.{name} is not {propertyName}
- XC0040
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/06b378b0a5798c67.
Report an issue: GitHub.