dotnet/maui · error · BuildException
XC0065
XC0065
Error message
Cannot set the content of "{0}" as it doesn't have a [ContentProperty] attribute. What it means
Thrown when a child element is placed directly in the content of a parent element (collection-item / implicit-content syntax) but the parent's type has no [ContentProperty] attribute and no applicable single-parameter Add method. Without the attribute the compiler cannot determine which property the inline content maps to.
Source
Thrown at src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs:161
Context.IL.Append(SetPropertyValue(Context.Variables[(ElementNode)parentNode], name, node, Context, node));
}
// Collection element, implicit content, or implicit collection element.
else if (parentVar.VariableType.ImplementsInterface(Context.Cache, Module.ImportReference(Context.Cache, ("mscorlib", "System.Collections", "IEnumerable")))
&& parentVar.VariableType.GetMethods(Context.Cache, md => md.Name == "Add" && md.Parameters.Count == 1, Module).Any())
{
var elementType = parentVar.VariableType;
var adderTuple = elementType.GetMethods(Context.Cache, md => md.Name == "Add" && md.Parameters.Count == 1, Module).First();
var adderRef = Module.ImportReference(adderTuple.Item1);
adderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
Context.IL.Emit(Ldloc, parentVar);
Context.IL.Append(vardef.LoadAs(Context.Cache, adderRef.Parameters[0].ParameterType.ResolveGenericParameters(adderRef), Module));
Context.IL.Emit(Callvirt, adderRef);
if (adderRef.ReturnType.FullName != "System.Void")
Context.IL.Emit(Pop);
}
else
throw new BuildException(ContentPropertyAttributeMissing, node, null, ((ElementNode)parentNode).XmlType.Name);
}
else if (IsCollectionItem(node, parentNode) && parentNode is ListNode node2)
{
// IL_000d: ldloc.2
// IL_000e: callvirt instance class [mscorlib]System.Collections.Generic.IList`1<!0> class [Microsoft.Maui.Controls]Microsoft.Maui.Controls.Layout`1<class [Microsoft.Maui.Controls]Microsoft.Maui.Controls.View>::get_Children()
// IL_0013: ldloc.0
// IL_0014: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<class [Microsoft.Maui.Controls]Microsoft.Maui.Controls.View>::Add(!0)
var parentList = node2;
var parent = Context.Variables[(ElementNode)parentList.Parent];
if (skips.Contains(parentList.XmlName))
return;
if (parentNode is ElementNode node3 && node3.SkipProperties.Contains(propertyName))
return;
var elementType = parent.VariableType;
var localname = parentList.XmlName.LocalName;
View on GitHub (pinned to f377ff1c5e)
Solutions
- Add [ContentProperty(nameof(ChildrenProperty))] to the parent type so inline content maps to a property.
- Wrap the child in an explicit property element, e.g. `<MyControl.Content><Label/></MyControl.Content>`.
- Use a control/collection type that already declares a content property or implements Add(T).
Example fix
<!-- before -->
<MyPanel>
<Label />
</MyPanel>
<!-- after: add attribute in C# -->
[ContentProperty(nameof(Children))]
public class MyPanel : Layout<View> { /* ... */ }
<!-- or wrap explicitly -->
<MyPanel>
<MyPanel.Children>
<Label />
</MyPanel.Children>
</MyPanel> Defensive patterns
Strategy: validation
Validate before calling
// Verify a type is usable as XAML content before putting children inline
static bool SupportsXamlContent(Type t)
=> t.GetCustomAttributes(true)
.Any(a => a.GetType().FullName == "System.Windows.Markup.ContentPropertyAttribute"); Prevention
- Add [ContentProperty] to custom container types that take inline children.
- When unsure, wrap children in explicit property elements.
- Document which property is the content property for custom controls.
When it happens
Trigger: A custom control or element used as a container with inline children, where the type lacks [ContentProperty(...)] and is not itself an IEnumerable-with-Add, e.g. `<MyControl><Label/></MyControl>` on a type with no ContentProperty attribute.
Common situations: Authoring a custom ContentView/Element and forgetting the [ContentProperty] attribute; using a type from another assembly that was not attributed for XAML content.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/3c1fd2f964c509af.
Report an issue: GitHub.