{"record":{"id":"526512408bbbceb1","repo":"dotnet/maui","slug":"xc0062","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/ExpandMarkupsVisitor.cs","lineNumber":132,"sourceCode":"\n\t\t\tpublic INode Parse(string match, ref string remaining, IServiceProvider serviceProvider)\n\t\t\t{\n\t\t\t\tif (!(serviceProvider.GetService(typeof(IXmlNamespaceResolver)) is IXmlNamespaceResolver nsResolver))\n\t\t\t\t\tthrow new ArgumentException();\n\t\t\t\tIXmlLineInfo xmlLineInfo = null;\n\t\t\t\tif (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider xmlLineInfoProvider)\n\t\t\t\t\txmlLineInfo = xmlLineInfoProvider.XmlLineInfo;\n\t\t\t\tvar contextProvider = serviceProvider.GetService(typeof(ILContextProvider)) as ILContextProvider;\n\n\t\t\t\tvar split = match.Split(':');\n\t\t\t\tif (split.Length > 2)\n\t\t\t\t\tthrow new ArgumentException();\n\n\t\t\t\tvar (prefix, name) = ParseName(match);\n\n\t\t\t\tvar namespaceuri = nsResolver.LookupNamespace(prefix) ?? \"\";\n\t\t\t\tif (!string.IsNullOrEmpty(prefix) && string.IsNullOrEmpty(namespaceuri))\n\t\t\t\t\tthrow new BuildException(BuildExceptionCode.XmlnsUndeclared, xmlLineInfo, null, prefix);\n\n\t\t\t\tIList<XmlType> typeArguments = null;\n\t\t\t\tvar childnodes = new List<(XmlName, INode)>();\n\t\t\t\tvar contentname = new XmlName(null, null);\n\n\t\t\t\tif (remaining.StartsWith(\"}\", StringComparison.Ordinal))\n\t\t\t\t{\n\t\t\t\t\tremaining = remaining.Substring(1);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tProperty parsed;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\ttry\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tparsed = ParseProperty(serviceProvider, ref remaining);\n\t\t\t\t\t\t}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/ExpandMarkupsVisitor.cs#L114-L150","documentation":"Thrown when a markup expression uses an XML namespace prefix that is not declared on any ancestor element. The parser looks up the prefix via nsResolver.LookupNamespace; if the prefix is non-empty but resolves to an empty URI, the type cannot be located and the build aborts.","triggerScenarios":"Writing '{local:MyExtension ...}' without xmlns:local declared on the root; typo in the prefix (e.g. 'loc' vs 'local'); prefix declared in a sibling scope but used outside it.","commonSituations":"Renaming an xmlns prefix in the root but not updating usage; copying XAML snippets between files that have different prefix mappings; declaring the xmlns on a child element where it is not in scope for the binding.","solutions":["Declare the missing xmlns prefix on the root element, e.g. xmlns:local=\"clr-namespace:MyApp.Controls\".","Correct the prefix spelling to match the declaration.","Move the xmlns declaration to a common ancestor that is in scope for the expression."],"exampleFix":"// before\n<ContentPage>   <!-- no xmlns:local -->\n  <Label Text=\"{local:Tr Key=Hello}\" />\n</ContentPage>\n// after\n<ContentPage xmlns:local=\"clr-namespace:MyApp.Markup\">\n  <Label Text=\"{local:Tr Key=Hello}\" />\n</ContentPage>","handlingStrategy":"validation","validationCode":"// Collect declared xmlns prefixes from the root and check usage\nstatic ISet<string> DeclaredPrefixes(XDocument doc) =>\n    doc.Root!.Attributes()\n       .Where(a => a.Name.NamespaceName == \"http://www.w3.org/2000/xmlns/\")\n       .Select(a => a.Name.LocalName).ToHashSet();\n\nstatic bool AllMarkupPrefixesDeclared(XDocument doc, ISet<string> prefixes) {\n    // naive: scan attribute values for '{prefix:' patterns\n    var used = Regex.Matches(doc.ToString(), @\"\\{(\\w+):\").Select(m => m.Groups[1].Value);\n    return used.All(prefixes.Contains);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare every xmlns prefix you reference on the root element.","Keep prefix names consistent across files via shared templates."],"tags":["xaml","xamlc","xmlns","namespace","markup-extension","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}