{"record":{"id":"96191859f6c77347","repo":"dotnet/wpf","slug":"sr-duplicatexmlnscompat","errorCode":null,"errorMessage":"SR.DuplicateXmlnsCompat","messagePattern":"SR\\.DuplicateXmlnsCompat","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs","lineNumber":349,"sourceCode":"                    // 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;\n            }\n\n            if (assembly.ReflectionOnly)\n            {\n                EnsureReflectionOnlyAttributeData();","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs#L331-L367","documentation":"System.Xaml throws XamlSchemaException(SR.DuplicateXmlnsCompat) when two XmlnsCompat attributes in the same assembly map the same old namespace. LoadOldToNewNs builds a dictionary keyed by old namespace; a second registration for an existing key is ambiguous and rejected.","triggerScenarios":"An assembly declares two [assembly: XmlnsCompat] attributes with identical oldns values; the second one hits result.ContainsKey(oldns) in LoadOldToNewNsHelper.","commonSituations":"Merging assemblies or copy-pasting compat attributes during a namespace migration, duplicated attributes in AssemblyInfo.cs across partial class/attribute files.","solutions":["Remove or unify the duplicated XmlnsCompat attributes so each old namespace is mapped exactly once.","Search AssemblyInfo files for repeated XmlnsCompat entries with the same first argument.","If both mappings are needed, choose one canonical old-namespace spelling."],"exampleFix":"// before (two attributes)\n[assembly: XmlnsCompat(\"clr-namespace:OldNs\", \"clr-namespace:NewNsA\")]\n[assembly: XmlnsCompat(\"clr-namespace:OldNs\", \"clr-namespace:NewNsB\")]\n// after (one)\n[assembly: XmlnsCompat(\"clr-namespace:OldNs\", \"clr-namespace:NewNsA\")]","handlingStrategy":"validation","validationCode":"var dupes = compatPairs.GroupBy(p => p.OldNs).Where(g => g.Count() > 1).ToList(); if (dupes.Any()) throw new InvalidOperationException($\"Duplicate XmlnsCompat old ns: {dupes[0].Key}\");","typeGuard":null,"tryCatchPattern":"try { loadXaml(); } catch (XamlSchemaException ex) when (ex.Message.Contains(\"DuplicateXmlnsCompat\")) { /* dedupe attributes */ }","preventionTips":["Grep assemblies for XmlnsCompat and keep one attribute per old namespace","Centralize compat attributes in a single AssemblyInfo file to avoid duplication"],"tags":["xaml","assembly-attributes","duplicate-key"],"backgroundTag":"conflicting-config-options","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"}