{"record":{"id":"a8c53a6036455f8f","repo":"dotnet/wpf","slug":"sr-badxmlnsprefix","errorCode":null,"errorMessage":"SR.BadXmlnsPrefix","messagePattern":"SR\\.BadXmlnsPrefix","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs","lineNumber":396,"sourceCode":"            }\n            else\n            {\n                Attribute[] attributes = Attribute.GetCustomAttributes(assembly, typeof(XmlnsPrefixAttribute));\n                foreach (Attribute attr in attributes)\n                {\n                    XmlnsPrefixAttribute xmlnsPrefixAttr = (XmlnsPrefixAttribute)attr;\n                    LoadPrefixesHelper(result, xmlnsPrefixAttr.XmlNamespace, xmlnsPrefixAttr.Prefix, assembly);\n                }\n            }\n\n            return result;\n        }\n\n        private void LoadPrefixesHelper(Dictionary<string, string> result, string xmlns, string prefix, Assembly assembly)\n        {\n            if (string.IsNullOrEmpty(prefix) || string.IsNullOrEmpty(xmlns))\n            {\n                throw new XamlSchemaException(SR.Format(SR.BadXmlnsPrefix, assembly.FullName));\n            }\n\n            string oldPrefix;\n            if (!result.TryGetValue(xmlns, out oldPrefix) ||\n                GetPreferredPrefix(oldPrefix, prefix) == prefix)\n            {\n                result[xmlns] = prefix;\n            }\n        }\n\n        private string LoadRootNamespace()\n        {\n            Assembly assembly = Assembly;\n            if (assembly is null)\n            {\n                return null;\n            }\n","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs#L378-L414","documentation":"System.Xaml throws XamlSchemaException(SR.BadXmlnsPrefix) while loading [assembly: XmlnsPrefix] attributes when the xmlns or prefix string is null or empty. Both values are required to declare a preferred prefix for a namespace.","triggerScenarios":"An assembly declares [assembly: XmlnsPrefix(\"\", \"p\")] or [assembly: XmlnsPrefix(\"clr-namespace:Ns\", \"\")]; LoadPrefixes -> LoadPrefixesHelper sees an empty value and throws.","commonSituations":"Hand-edited AssemblyInfo attributes, designer tooling emitting empty prefix values, refactors that cleared one argument.","solutions":["Provide non-empty xmlns and prefix strings in the XmlnsPrefix attribute.","Remove the attribute if no preferred prefix is intended.","Validate attribute constants are populated before shipping."],"exampleFix":"// before\n[assembly: System.Windows.Markup.XmlnsPrefix(\"clr-namespace:Ns\", \"\")]\n// after\n[assembly: System.Windows.Markup.XmlnsPrefix(\"clr-namespace:Ns\", \"controls\")]","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(xmlns) || string.IsNullOrEmpty(prefix)) throw new InvalidOperationException(\"XmlnsPrefix requires non-empty xmlns and prefix\");","typeGuard":null,"tryCatchPattern":"try { loadXaml(); } catch (XamlSchemaException ex) when (ex.Message.Contains(\"BadXmlnsPrefix\")) { /* fix attributes */ }","preventionTips":["Verify XmlnsPrefix attributes when adding new control libraries","Keep xmlns/prefix values as named constants"],"tags":["xaml","assembly-attributes","namespace-mapping"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}