{"record":{"id":"af17ebde15000b5c","repo":"dotnet/wpf","slug":"sr-badxmlnscompat","errorCode":null,"errorMessage":"SR.BadXmlnsCompat","messagePattern":"SR\\.BadXmlnsCompat","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs","lineNumber":344,"sourceCode":"            else\n            {\n                Attribute[] attributes = Attribute.GetCustomAttributes(assembly, typeof(XmlnsCompatibleWithAttribute));\n                foreach (Attribute attr in attributes)\n                {\n                    // Read in the attribute value\n                    XmlnsCompatibleWithAttribute xmlnsCompatAttr = (XmlnsCompatibleWithAttribute)attr;\n                    LoadOldToNewNsHelper(result, xmlnsCompatAttr.OldNamespace, xmlnsCompatAttr.NewNamespace, assembly);\n                }\n            }\n\n            return result;\n        }\n\n        private void LoadOldToNewNsHelper(Dictionary<string, string> result, string oldns, string newns, Assembly assembly)\n        {\n            if (string.IsNullOrEmpty(newns) || string.IsNullOrEmpty(oldns))\n            {\n                throw new XamlSchemaException(SR.Format(SR.BadXmlnsCompat, assembly.FullName));\n            }\n\n            if (result.ContainsKey(oldns))\n            {\n                throw new XamlSchemaException(SR.Format(SR.DuplicateXmlnsCompat, assembly.FullName, oldns));\n            }\n\n            result.Add(oldns, newns);\n        }\n\n        private Dictionary<string, string> LoadPrefixes()\n        {\n            Dictionary<string, string> result = new Dictionary<string, string>(StringComparer.Ordinal);\n\n            Assembly assembly = Assembly;\n            if (assembly is null)\n            {\n                return result;","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs#L326-L362","documentation":"System.Xaml throws XamlSchemaException(SR.BadXmlnsCompat) while loading [assembly: XmlnsCompat] attributes when either the old or new CLR namespace string is null or empty. The attribute is used to map old namespaces to new ones for forward compatibility, so both values must be non-empty to build the mapping.","triggerScenarios":"An assembly declares [assembly: XmlnsCompat(\"clr-namespace:OldNs\", \"\", typeof(...))] or omits one of the namespace strings; LoadOldToNewNs -> LoadOldToNewNsHelper then encounters an empty oldns/newns while building the xmlns compat dictionary.","commonSituations":"Hand-written assembly attributes after a namespace refactor, typos leaving one argument empty, code-generated attributes where a namespace constant resolved to empty string.","solutions":["Fill in both the old and new CLR namespace strings in the XmlnsCompat attribute.","Remove the XmlnsCompat attribute entirely if no namespace mapping is intended.","Verify the constants used for the attribute values are non-empty at compile time."],"exampleFix":"// before\n[assembly: System.Windows.Markup.XmlnsCompat(\"\", \"clr-namespace:NewNs\")]\n// after\n[assembly: System.Windows.Markup.XmlnsCompat(\"clr-namespace:OldNs\", \"clr-namespace:NewNs\")]","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(oldNs) || string.IsNullOrEmpty(newNs)) throw new InvalidOperationException(\"XmlnsCompat requires non-empty old and new namespaces\");","typeGuard":null,"tryCatchPattern":"try { loader.Load(stream); } catch (XamlSchemaException ex) when (ex.Message.Contains(\"XmlnsCompat\")) { /* fix assembly attributes */ }","preventionTips":["Use const strings for namespace values so emptiness is caught at compile time","Review AssemblyInfo attributes after every namespace refactor"],"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-22T01:17:13.364Z"}