{"record":{"id":"90d406ceecb3a078","repo":"dotnet/wpf","slug":"sr-format-sr-prefixnotfound-propname-prefix","errorCode":null,"errorMessage":"SR.Format(SR.PrefixNotFound, propName.Prefix)","messagePattern":"SR\\.Format\\(SR\\.PrefixNotFound, propName\\.Prefix\\)","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs","lineNumber":87,"sourceCode":"        /// </summary>\n        /// <param name=\"tagType\">The xamlType of the enclosing Tag</param>\n        /// <param name=\"tagNamespace\">The namespace of the enclosing Tag</param>\n        /// <param name=\"propName\">The dotted name of the property</param>\n        /// <param name=\"tagIsRoot\">Whether the tag is the root of the document</param>\n        /// <returns></returns>\n        public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot)\n        {\n            if (tagType is null)\n            {\n                throw new XamlInternalException(SR.Format(SR.ParentlessPropertyElement, propName.ScopedName));\n            }\n\n            XamlMember property = null;\n            XamlType ownerType = null;\n            string ns = ResolveXamlNameNS(propName);\n            if (ns is null)\n            {\n                throw new XamlParseException(SR.Format(SR.PrefixNotFound, propName.Prefix));\n            }\n\n            XamlType rootTagType = tagIsRoot ? tagType : null;\n\n            // If we have <foo x:TA=\"\" foo.bar=\"\"/> we want foo in foo.bar to match the tag\n            // type since there is no way to specify generic syntax in dotted property notation\n            // If that fails, then we fall back to the non-generic case below.\n            bool ownerTypeMatchesGenericTagType = false;\n            if (tagType.IsGeneric)\n            {\n                ownerTypeMatchesGenericTagType = PropertyTypeMatchesGenericTagType(tagType, tagNamespace, ns, propName.OwnerName);\n                if (ownerTypeMatchesGenericTagType)\n                {\n                    property = GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType);\n                    if (property is not null)\n                    {\n                        return property;\n                    }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs#L69-L105","documentation":"GetDottedProperty resolves the namespace of a dotted property name via ResolveXamlNameNS; when the prefix cannot be mapped to a namespace, it throws XamlParseException with PrefixNotFound carrying the unknown prefix.","triggerScenarios":"A dotted property attribute/element uses an xmlns prefix that is not declared (e.g. <controls:Foo.Text> with no xmlns:controls declaration in scope).","commonSituations":"Copy-pasting XAML snippets into another file without copying the xmlns declarations; renaming a prefix in one place but not others; merged XAML fragments missing namespace imports.","solutions":["Add the missing xmlns declaration: xmlns:controls=\"clr-namespace:MyNs;assembly=MyAssembly\" on the root or nearest element.","Correct the prefix in the dotted name to match an existing declaration.","If the prefix maps to an assembly not referenced, add the project/package reference.","Catch XamlParseException, extract the prefix from the message, and report the undeclared namespace to the author."],"exampleFix":"// before\n<StackPanel><local:Widget.Label>hi</local:Widget.Label></StackPanel> <!-- local undeclared -->\n// after\n<StackPanel xmlns:local=\"clr-namespace:App.Views;assembly=App\">\n  <local:Widget.Label>hi</local:Widget.Label>\n</StackPanel>","handlingStrategy":"validation","validationCode":"// ensure all prefixes used in element/attribute names are declared\nvar declared = root.Attributes().Where(a => a.IsNamespaceDeclaration).Select(a => a.Name.LocalName);\nvar used = doc.Descendants().Attributes().SelectMany(a => a.Name.NamespaceName == \"\" ? new[]{a.Name.LocalName.Split('.').First().Split(':').First()} : Enumerable.Empty<string>());\nvar missing = used.Except(declared).ToList();","typeGuard":"bool PrefixDeclared(XDocument doc, string prefix) => doc.Root.Attributes().Any(a => a.IsNamespaceDeclaration && a.Name.LocalName == prefix);","tryCatchPattern":"try { LoadXaml(xamlText); }\ncatch (XamlParseException ex) when (ex.Message.Contains(\"prefix\")) { // undeclared xmlns prefix\n  throw new FormatException(\"Declare the missing xmlns prefix: \" + ex.Message, ex); }","preventionTips":["Copy xmlns declarations together with pasted XAML","Grep used prefixes against declared xmlns before building","Keep prefix names consistent across files"],"tags":["wpf","system-xaml","xaml-parse","xml-namespace","undeclared-prefix"],"backgroundTag":"resource-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}