{"record":{"id":"3c1fd2f964c509af","repo":"dotnet/maui","slug":"xc0065","errorCode":"XC0065","errorMessage":"Cannot set the content of \"{0}\" as it doesn't have a [ContentProperty] attribute.","messagePattern":"Cannot set the content of \"(.+?)\" as it doesn't have a \\[ContentProperty\\] attribute\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs","lineNumber":161,"sourceCode":"\t\t\t\t\tContext.IL.Append(SetPropertyValue(Context.Variables[(ElementNode)parentNode], name, node, Context, node));\n\t\t\t\t}\n\t\t\t\t// Collection element, implicit content, or implicit collection element.\n\t\t\t\telse if (parentVar.VariableType.ImplementsInterface(Context.Cache, Module.ImportReference(Context.Cache, (\"mscorlib\", \"System.Collections\", \"IEnumerable\")))\n\t\t\t\t\t\t && parentVar.VariableType.GetMethods(Context.Cache, md => md.Name == \"Add\" && md.Parameters.Count == 1, Module).Any())\n\t\t\t\t{\n\t\t\t\t\tvar elementType = parentVar.VariableType;\n\t\t\t\t\tvar adderTuple = elementType.GetMethods(Context.Cache, md => md.Name == \"Add\" && md.Parameters.Count == 1, Module).First();\n\t\t\t\t\tvar adderRef = Module.ImportReference(adderTuple.Item1);\n\t\t\t\t\tadderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));\n\n\t\t\t\t\tContext.IL.Emit(Ldloc, parentVar);\n\t\t\t\t\tContext.IL.Append(vardef.LoadAs(Context.Cache, adderRef.Parameters[0].ParameterType.ResolveGenericParameters(adderRef), Module));\n\t\t\t\t\tContext.IL.Emit(Callvirt, adderRef);\n\t\t\t\t\tif (adderRef.ReturnType.FullName != \"System.Void\")\n\t\t\t\t\t\tContext.IL.Emit(Pop);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tthrow new BuildException(ContentPropertyAttributeMissing, node, null, ((ElementNode)parentNode).XmlType.Name);\n\t\t\t}\n\t\t\telse if (IsCollectionItem(node, parentNode) && parentNode is ListNode node2)\n\t\t\t{\n\t\t\t\t//\t\t\t\tIL_000d:  ldloc.2 \n\t\t\t\t//\t\t\t\tIL_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()\n\t\t\t\t//\t\t\t\tIL_0013:  ldloc.0 \n\t\t\t\t//\t\t\t\tIL_0014:  callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<class [Microsoft.Maui.Controls]Microsoft.Maui.Controls.View>::Add(!0)\n\n\t\t\t\tvar parentList = node2;\n\t\t\t\tvar parent = Context.Variables[(ElementNode)parentList.Parent];\n\n\t\t\t\tif (skips.Contains(parentList.XmlName))\n\t\t\t\t\treturn;\n\t\t\t\tif (parentNode is ElementNode node3 && node3.SkipProperties.Contains(propertyName))\n\t\t\t\t\treturn;\n\t\t\t\tvar elementType = parent.VariableType;\n\t\t\t\tvar localname = parentList.XmlName.LocalName;\n","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs#L143-L179","documentation":"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.","triggerScenarios":"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.","commonSituations":"Authoring a custom ContentView/Element and forgetting the [ContentProperty] attribute; using a type from another assembly that was not attributed for XAML content.","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)."],"exampleFix":"<!-- before -->\n<MyPanel>\n  <Label />\n</MyPanel>\n\n<!-- after: add attribute in C# -->\n[ContentProperty(nameof(Children))]\npublic class MyPanel : Layout<View> { /* ... */ }\n\n<!-- or wrap explicitly -->\n<MyPanel>\n  <MyPanel.Children>\n    <Label />\n  </MyPanel.Children>\n</MyPanel>","handlingStrategy":"validation","validationCode":"// Verify a type is usable as XAML content before putting children inline\nstatic bool SupportsXamlContent(Type t)\n    => t.GetCustomAttributes(true)\n        .Any(a => a.GetType().FullName == \"System.Windows.Markup.ContentPropertyAttribute\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["xaml","xamlc","content-property","custom-control"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}