{"record":{"id":"dcfc881dd66d6715","repo":"dotnet/maui","slug":"xc0062-dcfc88","errorCode":"XC0062","errorMessage":"Undeclared xmlns prefix \"{0}\".","messagePattern":"Undeclared xmlns prefix \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs","lineNumber":587,"sourceCode":"\t\t\t\t\t&& enode.XmlType.Name == nameof(Xaml.NullExtension))\n\t\t\t\t{\n\t\t\t\t\tcontext.LoggingHelper.LogWarningOrError(BindingWithNullDataType, context.XamlFilePath, node.LineNumber, node.LinePosition, 0, 0, null);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif ((dataTypeNode as ValueNode)?.Value is not string dataType)\n\t\t\t\t\tthrow new BuildException(XDataTypeSyntax, dataTypeNode as IXmlLineInfo, null);\n\n\t\t\t\tXmlType dtXType = null;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tdtXType = TypeArgumentsParser.ParseSingle(dataType, node.NamespaceResolver, dataTypeNode as IXmlLineInfo)\n\t\t\t\t\t\t?? throw new BuildException(XDataTypeSyntax, dataTypeNode as IXmlLineInfo, null);\n\t\t\t\t}\n\t\t\t\tcatch (XamlParseException)\n\t\t\t\t{\n\t\t\t\t\tvar prefix = dataType.Contains(\":\") ? dataType.Substring(0, dataType.IndexOf(\":\", StringComparison.Ordinal)) : \"\";\n\t\t\t\t\tthrow new BuildException(XmlnsUndeclared, dataTypeNode as IXmlLineInfo, null, prefix);\n\t\t\t\t}\n\n\t\t\t\ttSourceRef = dtXType.GetTypeReference(context.Cache, module, (IXmlLineInfo)node);\n\t\t\t\tif (tSourceRef == null)\n\t\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (tSourceRef == null)\n\t\t\t\treturn false; //throw\n\n\t\t\tif (!TryParsePath(context, path, tSourceRef, node as IXmlLineInfo, module, out var properties, suppressPropertyNotFoundError: tSourceRefIsAncestorTypeInferred))\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tinstructions = GenerateInstructions();\n\t\t\treturn true;\n","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs#L569-L605","documentation":"Thrown when parsing the x:DataType type expression raises a XamlParseException because the xmlns prefix used is not declared. The compiler extracts the prefix portion (before ':') from the DataType string and reports it as undeclared.","triggerScenarios":"x:DataType=\"prefix:Type\" where `prefix` does not appear in any xmlns declaration on the element or its ancestors.","commonSituations":"Forgetting to add the xmlns declaration for the view-model namespace; typo in the prefix; prefix declared in a different scope than expected.","solutions":["Add the matching xmlns declaration, e.g. xmlns:vm=\"clr-namespace:App.ViewModels\" (or an assembly-qualified url).","Check the prefix spelling in both the xmlns declaration and the x:DataType value.","Ensure the xmlns is declared on an ancestor in scope (typically the page/root element)."],"exampleFix":"<!-- before -->\n<ContentPage x:DataType=\"vm:MainViewModel\">\n\n<!-- after -->\n<ContentPage xmlns:vm=\"clr-namespace:App.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">","handlingStrategy":"validation","validationCode":"// Ensure every prefix used in x:DataType is declared as an xmlns\nstatic bool PrefixDeclared(string dataTypeValue, IEnumerable<string> declaredPrefixes)\n{\n    var prefix = dataTypeValue.Contains(':')\n        ? dataTypeValue.Substring(0, dataTypeValue.IndexOf(':')) : null;\n    return prefix == null || declaredPrefixes.Contains(prefix);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare the xmlns for the view-model namespace on the page/root element.","Keep prefix spelling consistent between xmlns and x:DataType.","Add xmlns declarations at the widest needed scope."],"tags":["xaml","xamlc","xmlns","x-datatype"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}