{"record":{"id":"8ce639aced799e1d","repo":"dotnet/maui","slug":"xc0003-8ce639","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/TypeExtension.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 TypeExtension : ICompiledMarkupExtension\n\t{\n\t\tpublic IEnumerable<Instruction> ProvideValue(ElementNode node, ModuleDefinition module, ILContext context, out TypeReference memberRef)\n\t\t{\n\t\t\tmemberRef = module.ImportReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"));\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 ValueNode valueNode))\n\t\t\t\tthrow new BuildException(BuildExceptionCode.PropertyMissing, node as IXmlLineInfo, null, \"TypeName\", typeof(Microsoft.Maui.Controls.Xaml.TypeExtension));\n\n\t\t\tif (!node.Properties.ContainsKey(name))\n\t\t\t{\n\t\t\t\tnode.Properties[name] = typeNameNode;\n\t\t\t\tnode.CollectionItems.Clear();\n\t\t\t}\n\n\t\t\tvar typeref = module.ImportReference(XmlTypeExtensions.GetTypeReference(context.Cache, valueNode.Value as string, module, node as BaseNode));\n\n\t\t\tcontext.TypeExtensions[node] = typeref ?? throw new BuildException(BuildExceptionCode.TypeResolution, node as IXmlLineInfo, null, valueNode.Value);\n\n\t\t\treturn new List<Instruction> {\n\t\t\t\tCreate(Ldtoken, module.ImportReference(typeref)),\n\t\t\t\tCreate(Call, module.ImportMethodReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  methodName: \"GetTypeFromHandle\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  parameterTypes: [(\"mscorlib\", \"System\", \"RuntimeTypeHandle\")],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t  isStatic: true)),\n\t\t\t};","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledMarkupExtensions/TypeExtension.cs#L5-L41","documentation":"Thrown by the compiled x:Type extension when the TypeName property (or the single inline collection item) is not a string literal ValueNode. x:Type needs a concrete type name string to import and emit a Type token; a missing or non-literal value makes emission impossible.","triggerScenarios":"Using <x:Type /> with no TypeName attribute and no inline text; binding TypeName to another markup extension or element node instead of a literal; whitespace-only content that fails the ValueNode cast.","commonSituations":"Authoring a DataTemplate or Style TargetType via x:Type and forgetting the type name; attempting to compute the type dynamically at build time; malformed XAML where the closing tag swallows the text.","solutions":["Provide TypeName=\"MyNamespace.MyType\" as an attribute, or put the type name as inline text content.","Ensure the xmlns prefix for the type's namespace is declared and used, e.g. TypeName=\"local:MyView\".","Verify the value is a plain string literal, not a nested element/marker.","If the type must be dynamic, do not use x:Type in compiled XAML; resolve it in code-behind."],"exampleFix":"// before\n<DataTemplate>\n  <x:Type />\n</DataTemplate>\n// after\n<DataTemplate>\n  <x:Type TypeName=\"local:MyView\" />\n</DataTemplate>","handlingStrategy":"validation","validationCode":"// Ensure x:Type has a literal TypeName\nstatic bool XTypeHasLiteralTypeName(XElement el) =>\n    el.Attribute(\"TypeName\") is { Value: { Length: > 0 } v }\n    || (!el.Elements().Any() && !string.IsNullOrWhiteSpace(el.Value));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide TypeName=\"...\" on x:Type with a declared xmlns prefix.","Avoid nesting markup inside x:Type; use a literal name only.","Resolve types dynamically in code-behind instead of compiled XAML."],"tags":["xaml","xamlc","x-type","type-resolution","markup-extension","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}