dotnet/wpf · error · XamlSchemaException

SR.DuplicateXmlnsCompatAcrossAssemblies

Error message

SR.DuplicateXmlnsCompatAcrossAssemblies

What it means

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.

Solutions

  1. Search referenced assemblies for XmlnsCompatibleWith on the old namespace and remove/align the conflicting mapping
  2. Ensure all assemblies remap the old namespace to the same new namespace
  3. Remove duplicate/stale XmlnsCompatibleWith attributes from one of the assemblies or unify package versions

Example fix

// before
[assembly: XmlnsCompatibleWith("clr-namespace:Old", "clr-namespace:NewA")] // Assembly1
[assembly: XmlnsCompatibleWith("clr-namespace:Old", "clr-namespace:NewB")] // Assembly2
// after: both assemblies use
[assembly: XmlnsCompatibleWith("clr-namespace:Old", "clr-namespace:NewA")]
Defensive patterns

Strategy: try-catch

Validate before calling

// audit assemblies for conflicting compat mappings before loading XAML
foreach (var asm in assemblies)
  foreach (var a in asm.GetCustomAttributes<XmlnsCompatibleWithAttribute>())
    track(oldNs -> newNs); // throw if a second, different newNs appears

Try / catch

try { ok = ctx.TryGetCompatibleXamlNamespace(oldNs, out newNs); } catch (XamlSchemaException ex) { Log("Conflicting XmlnsCompatibleWith mappings: " + ex.Message); }

Prevention

When it happens

Trigger: Calling TryGetCompatibleXamlNamespace when at least two referenced assemblies declare [assembly: XmlnsCompatibleWith(oldNs, newNsA)] and (oldNs, newNsB) with newNsA != newNsB.

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/2c7d7f7c77b6776d. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs:468

                            {
                                throw;
                            }

                            // just skip to the next assembly
                            continue;
                        }
                    }
                    else
                    {
                        oldToNewNs = nsInfo.OldToNewNs;
                    }

                    string newNs;
                    if (oldToNewNs.TryGetValue(oldNs, out newNs))
                    {
                        if (result is not null && result != newNs)
                        {
                            throw new XamlSchemaException(SR.Format(SR.DuplicateXmlnsCompatAcrossAssemblies,
                                resultAssembly.FullName, curAssembly.FullName, oldNs));
                        }

                        result = newNs;
                        resultAssembly = curAssembly;
                    }
                }
            }

            return result;
        }

        #endregion

        #region Type and member cache

        // Lazy init, access these fields through the properties
        private ConcurrentDictionary<Type, XamlType> _masterTypeList;

View on GitHub (pinned to 81131a70a4)