{"record":{"id":"2c7d7f7c77b6776d","repo":"dotnet/wpf","slug":"sr-duplicatexmlnscompatacrossassemblies","errorCode":null,"errorMessage":"SR.DuplicateXmlnsCompatAcrossAssemblies","messagePattern":"SR\\.DuplicateXmlnsCompatAcrossAssemblies","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs","lineNumber":468,"sourceCode":"                            {\n                                throw;\n                            }\n\n                            // just skip to the next assembly\n                            continue;\n                        }\n                    }\n                    else\n                    {\n                        oldToNewNs = nsInfo.OldToNewNs;\n                    }\n\n                    string newNs;\n                    if (oldToNewNs.TryGetValue(oldNs, out newNs))\n                    {\n                        if (result is not null && result != newNs)\n                        {\n                            throw new XamlSchemaException(SR.Format(SR.DuplicateXmlnsCompatAcrossAssemblies,\n                                resultAssembly.FullName, curAssembly.FullName, oldNs));\n                        }\n\n                        result = newNs;\n                        resultAssembly = curAssembly;\n                    }\n                }\n            }\n\n            return result;\n        }\n\n        #endregion\n\n        #region Type and member cache\n\n        // Lazy init, access these fields through the properties\n        private ConcurrentDictionary<Type, XamlType> _masterTypeList;","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs#L450-L486","documentation":"XamlSchemaContext.GetCompatibleNamespace collects XmlnsCompatibleWith mappings across loaded assemblies. If two different assemblies map the same old namespace to different new namespaces, the result is ambiguous and XamlSchemaException is thrown, naming both assemblies and the old namespace.","triggerScenarios":"Calling TryGetCompatibleXamlNamespace when at least two referenced assemblies declare [assembly: XmlnsCompatibleWith(oldNs, newNsA)] and (oldNs, newNsB) with newNsA != newNsB.","commonSituations":"Merging two component libraries that both remapped the same legacy CLR namespace; copy-pasted XmlnsCompatibleWith attributes left stale after a namespace migration; NuGet package version conflicts shipping duplicate compat attributes.","solutions":["Search referenced assemblies for XmlnsCompatibleWith on the old namespace and remove/align the conflicting mapping","Ensure all assemblies remap the old namespace to the same new namespace","Remove duplicate/stale XmlnsCompatibleWith attributes from one of the assemblies or unify package versions"],"exampleFix":"// before\n[assembly: XmlnsCompatibleWith(\"clr-namespace:Old\", \"clr-namespace:NewA\")] // Assembly1\n[assembly: XmlnsCompatibleWith(\"clr-namespace:Old\", \"clr-namespace:NewB\")] // Assembly2\n// after: both assemblies use\n[assembly: XmlnsCompatibleWith(\"clr-namespace:Old\", \"clr-namespace:NewA\")]","handlingStrategy":"try-catch","validationCode":"// audit assemblies for conflicting compat mappings before loading XAML\nforeach (var asm in assemblies)\n  foreach (var a in asm.GetCustomAttributes<XmlnsCompatibleWithAttribute>())\n    track(oldNs -> newNs); // throw if a second, different newNs appears","typeGuard":null,"tryCatchPattern":"try { ok = ctx.TryGetCompatibleXamlNamespace(oldNs, out newNs); } catch (XamlSchemaException ex) { Log(\"Conflicting XmlnsCompatibleWith mappings: \" + ex.Message); }","preventionTips":["Keep one canonical XmlnsCompatibleWith mapping per old namespace across all assemblies","Audit NuGet dependency duplicates for stale compat attributes","Centralize namespace migrations in a single shared assembly"],"tags":["xaml","namespace","assembly-attributes","conflict","wpf"],"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-21T21:30:21.729Z"}