{"record":{"id":"9bbf098618889f70","repo":"dotnet/maui","slug":"xc0003","errorCode":"XC0003","errorMessage":"Missing mandatory property \"{0}\" on \"{1}\".","messagePattern":"Missing mandatory property \"(.+?)\" on \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledMarkupExtensions/DataTemplateExtension.cs","lineNumber":23,"sourceCode":"using Mono.Cecil;\nusing Mono.Cecil.Cil;\nusing static Mono.Cecil.Cil.Instruction;\nusing static Mono.Cecil.Cil.OpCodes;\n\nnamespace Microsoft.Maui.Controls.Build.Tasks\n{\n\tclass DataTemplateExtension : ICompiledMarkupExtension\n\t{\n\t\tpublic IEnumerable<Instruction> ProvideValue(ElementNode node, ModuleDefinition module, ILContext context, out TypeReference typeRef)\n\t\t{\n\t\t\ttypeRef = module.ImportReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls\", \"DataTemplate\"));\n\t\t\tvar name = new XmlName(\"\", \"TypeName\");\n\n\t\t\tif (!node.Properties.TryGetValue(name, out INode typeNameNode) && node.CollectionItems.Any())\n\t\t\t\ttypeNameNode = node.CollectionItems[0];\n\n\t\t\tif (typeNameNode is not ValueNode valueNode)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.PropertyMissing, node as IXmlLineInfo, null, \"TypeName\", typeof(Microsoft.Maui.Controls.Xaml.DataTemplateExtension));\n\n\t\t\tvar contentTypeRef = module.ImportReference(XmlTypeExtensions.GetTypeReference(context.Cache, valueNode.Value as string, module, node as BaseNode))\n\t\t\t\t?? throw new BuildException(BuildExceptionCode.TypeResolution, node as IXmlLineInfo, null, valueNode.Value);\n\n\t\t\tvar dataTemplateCtor = module.ImportCtorReference(context.Cache, typeRef, new[] { module.ImportReference(context.Cache, (\"mscorlib\", \"System\", \"Type\")) });\n\t\t\treturn [\n\t\t\t\tCreate(Ldtoken, module.ImportReference(contentTypeRef)),\n\t\t\t\tCreate(Call, module.ImportMethodReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"), methodName: \"GetTypeFromHandle\", parameterTypes: new[] { (\"mscorlib\", \"System\", \"RuntimeTypeHandle\") }, isStatic: true)),\n\t\t\t\tCreate(Newobj, dataTemplateCtor),\n\t\t\t];\n\t\t}\n\t}\n}\n","sourceCodeStart":5,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledMarkupExtensions/DataTemplateExtension.cs#L5-L37","documentation":"XC0003 PropertyMissing thrown by the DataTemplateExtension compiled markup extension when the required 'TypeName' property is absent. The extension first checks node.Properties for a 'TypeName' key, then falls back to the first collection item. If neither yields a ValueNode (e.g. the property is missing and there are no collection items, or the item is an element node rather than a value), the build fails.","triggerScenarios":"Using {DataTemplate} markup extension without specifying TypeName, or providing a non-value node where TypeName is expected. The extension requires either TypeName=\"MyType\" as an attribute or a inline value as the first child item.","commonSituations":"Forgetting to include TypeName when using the {DataTemplate} extension. Providing a complex element instead of a simple type-name string. Confusing this compiled extension with the runtime DataTemplate API which accepts a Type object directly.","solutions":["Add the TypeName attribute to the DataTemplate extension usage, e.g. {DataTemplate TypeName='local:MyView'}.","Ensure the TypeName value is a simple string (ValueNode) representing a type reference, not a nested element.","If using inline syntax, ensure the first child item is a value node with the type name."],"exampleFix":"<!-- before -->\n<DataTemplate />\n\n<!-- after -->\n<DataTemplate TypeName=\"local:MyItemView\" />","handlingStrategy":"validation","validationCode":"// Validate that a DataTemplate extension node has a TypeName property or collection item\nstatic bool HasTypeNameValue(IDictionary<XmlName, INode> properties, IList<INode> collectionItems)\n    => (properties.TryGetValue(new XmlName(\"\", \"TypeName\"), out var node) && node is ValueNode)\n       || (collectionItems.Any() && collectionItems[0] is ValueNode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include TypeName when using the {DataTemplate} compiled markup extension.","Provide TypeName as a simple string attribute value, not a nested element.","Distinguish this compiled extension from the runtime DataTemplate(Type) constructor."],"tags":["xaml","maui","xamlc","markup-extension","datatemplate","property-missing","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}