{"record":{"id":"dbb83e0eac6c2fc8","repo":"dotnet/wpf","slug":"sr-requiresxmlnamespacemapping-formatted-with-value-type","errorCode":null,"errorMessage":"SR.RequiresXmlNamespaceMapping (formatted with value type name)","messagePattern":"SR\\.RequiresXmlNamespaceMapping \\(formatted with value type name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMappingCollection.cs","lineNumber":50,"sourceCode":"        /// <summary>\n        /// IAddChild implementation\n        /// <see cref=\"IAddChild\"/>\n        /// </summary>\n        /// <param name=\"value\"></param>\n        void IAddChild.AddChild(object value)\n        {\n            AddChild(value);\n        }\n\n        /// <summary>\n        /// IAddChild implementation\n        /// </summary>\n        /// <param name=\"value\"></param>\n        protected virtual void AddChild(object value)\n        {\n            XmlNamespaceMapping mapping = value as XmlNamespaceMapping;\n            if (mapping == null)\n                throw new ArgumentException(SR.Format(SR.RequiresXmlNamespaceMapping, value.GetType().FullName), nameof(value));\n\n            Add(mapping);\n        }\n\n        /// <summary>\n        /// IAddChild implementation\n        /// </summary>\n        /// <param name=\"text\"></param>\n        void IAddChild.AddText(string text)\n        {\n            AddText(text);\n        }\n\n        /// <summary>\n        /// IAddChild implementation\n        /// </summary>\n        /// <param name=\"text\"></param>\n        protected virtual void AddText(string text)","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMappingCollection.cs#L32-L68","documentation":"XmlNamespaceMappingCollection.AddChild (the IAddChild content path used by XAML) only accepts XmlNamespaceMapping instances. If the supplied object is of any other type, it throws an ArgumentException with SR.RequiresXmlNamespaceMapping formatted with the value's actual type name.","triggerScenarios":"Adding a child to an XmlNamespaceMappingCollection in XAML or via AddChild that is not an <XmlNamespaceMapping> element, e.g. a plain string or wrong element type.","commonSituations":"XAML content-element typo (nesting the wrong element inside XmlNamespaceMapping); code calling AddChild directly with a string prefix instead of a mapping object.","solutions":["Only place XmlNamespaceMapping elements inside the collection.","Call collection.Add(new XmlNamespaceMapping(prefix, uri)) in code instead of AddChild with raw values.","Check the element type in XAML; a typo like <Prefix> as a direct child is not supported."],"exampleFix":"// before\nxmlDataProvider.XmlNamespaceMapper... // AddChild(\"atom\"); // throws\n// after\nvar mapping = new XmlNamespaceMapping(\"atom\", new Uri(\"http://www.w3.org/2005/Atom\"));\ncollection.Add(mapping);","handlingStrategy":"type-guard","validationCode":"if (child is not XmlNamespaceMapping) throw new ArgumentException(\"Only XmlNamespaceMapping children are supported\", nameof(child));","typeGuard":"static bool IsNamespaceMapping(object value) => value is XmlNamespaceMapping;","tryCatchPattern":"try { collection.AddChild(value); }\ncatch (ArgumentException ex) { log.Error(\"XmlNamespaceMappingCollection requires XmlNamespaceMapping children\", ex); }","preventionTips":["Only place <XmlNamespaceMapping> elements as collection children in XAML.","Call the typed Add(XmlNamespaceMapping) overload instead of AddChild in code.","Validate element types in XAML when building collections dynamically."],"tags":["wpf","xml","type-mismatch","xaml"],"backgroundTag":"type-mismatch","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"}