{"record":{"id":"d26cc26ef3628345","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-xmlnamespace","errorCode":null,"errorMessage":"ArgumentNullException(nameof(xmlNamespace))","messagePattern":"ArgumentNullException\\(nameof\\(xmlNamespace\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":105,"sourceCode":"        /// </summary>\n        /// <remarks>\n        /// Example:<para/>\n        ///     If the xml contained the tags <base:Button xmlns:base=\"AvalonBase\"/>\n        ///     you would call XamlTypeMapper.GetType(\"AvalonBase\",\"Button\");\n        ///     <para/>\n        ///     Note the XmlNamespace \"AvalonBase\" is the actual namespace value, not\n        ///     the base: prefix.\n        /// </remarks>\n        /// <param name=\"xmlNamespace\">NamespaceURI of tag</param>\n        /// <param name=\"localName\">localName of the Tag</param>\n        /// <returns>Type for the object. If no type was found NULL is returned</returns>\n        public Type GetType(\n            string xmlNamespace,\n            string localName)\n        {\n            if(null == xmlNamespace)\n            {\n                throw new ArgumentNullException( nameof(xmlNamespace));\n            }\n            if(null == localName)\n            {\n                throw new ArgumentNullException( nameof(localName));\n            }\n\n            TypeAndSerializer typeAndSerializer =\n                GetTypeOnly(xmlNamespace,localName);\n\n            return typeAndSerializer?.ObjectType;\n        }\n\n#if !PBTCOMPILER\n        /// <summary>\n        ///  Programmatic counterpart to the <?Mapping ... ?> XAML PI.  For example, <para/>\n        ///    <?Mapping XmlNamespace=\"swc\" ClrNamespace=\"System.Windows.ComponentModel\" Assembly=\"PresentationFramework\" ?>\n        /// </summary>\n        /// <param name=\"xmlNamespace\">","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L87-L123","documentation":"XamlTypeMapper.GetType(xmlNamespace, localName) resolves a XAML namespace plus local type name to a CLR Type. It validates both parameters and throws ArgumentNullException when xmlNamespace is null. The namespace is the key used to look up the cached TypeAndSerializer entry, so a null namespace cannot be resolved.","triggerScenarios":"Calling mapper.GetType(null, \"Button\") — passing a null XML namespace string directly to XamlTypeMapper.GetType, typically from custom GetTypeFromBaseString or GetTypeArgsType logic.","commonSituations":"Custom markup extension or type-resolution code derives the namespace from a parsed XAML node that had no xmlns in scope, or from an XmlnsDictionary lookup that returned null.","solutions":["Ensure the xmlNamespace string is non-null before calling GetType; use String.Empty for the default namespace if appropriate.","Resolve the namespace from the ParserContext's XmlnsDictionary and fall back to a known constant (e.g. XamlReaderHelper.DefaultNamespace) when absent.","Wrap the call and convert the ArgumentNullException into a domain-specific error identifying the malformed XAML node."],"exampleFix":"// before\nType t = mapper.GetType(node.Namespace, node.LocalName); // node.Namespace may be null\n// after\nstring ns = node.Namespace ?? XamlReaderHelper.DefaultNamespace;\nType t = mapper.GetType(ns, node.LocalName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(xmlNamespace))\n    xmlNamespace = XamlReaderHelper.DefaultNamespace; // or skip the lookup","typeGuard":"static bool CanResolve(string xmlNamespace, string localName) =>\n    xmlNamespace != null && localName != null;","tryCatchPattern":"try\n{\n    type = mapper.GetType(xmlNamespace, localName);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"xmlNamespace\")\n{\n    throw new XamlParseException($\"Element '{localName}' has no xmlns in scope\", ex);\n}","preventionTips":["Resolve namespaces via ParserContext.XmlnsDictionary which handles defaults","Never forward raw parsed XAML node namespace values without a null check","Keep a default-namespace constant for elements with no xmlns declaration"],"tags":["wpf","xaml","argument-null","type-resolution"],"backgroundTag":"null-argument","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"}