{"record":{"id":"efe7ef9663b1f880","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-xmlnamespace","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(xmlNamespace));","messagePattern":"throw new ArgumentNullException\\(nameof\\(xmlNamespace\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":4230,"sourceCode":"        #region Constructors\n\n        ///<summary>\n        /// NamespaceMapEntry default constructor\n        ///</summary>\n        public NamespaceMapEntry()\n        {\n        }\n\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"xmlNamespace\">The XML NamespaceURi</param>\n        /// <param name=\"assemblyName\">Assembly to use when resolving a Tag</param>\n        /// <param name=\"clrNamespace\">Namespace within the assembly</param>\n        public NamespaceMapEntry(string xmlNamespace,string assemblyName,string clrNamespace)\n        {\n            if (xmlNamespace == null)\n                throw new ArgumentNullException(nameof(xmlNamespace));\n\n            if (assemblyName == null)\n                throw new ArgumentNullException(nameof(assemblyName));\n\n            if (clrNamespace == null)\n                throw new ArgumentNullException(nameof(clrNamespace));\n\n            _xmlNamespace = xmlNamespace;\n            _assemblyName = assemblyName;\n            _clrNamespace = clrNamespace;\n        }\n\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"xmlNamespace\">The XML NamespaceURi</param>\n        /// <param name=\"assemblyName\">Assembly to use when resolving a Tag</param>\n        /// <param name=\"clrNamespace\">Namespace within the assembly</param>","sourceCodeStart":4212,"sourceCodeEnd":4248,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L4212-L4248","documentation":"The NamespaceMapEntry constructor validates its three string parameters and throws ArgumentNullException when xmlNamespace is null. A namespace map entry associates an XML namespace with an assembly and CLR namespace for XAML type resolution; the xmlNamespace is the primary key, so null is rejected.","triggerScenarios":"Constructing new NamespaceMapEntry(null, assemblyName, clrNamespace) — typically when the namespace URI came from an unparsed xmlns attribute or a lookup that returned null.","commonSituations":"Building custom XAML schema contexts in designers; programmatically registering namespace maps where xmlns declarations were missing from source XAML.","solutions":["Pass the XML namespace URI string as the first constructor argument","Read the namespace from the parsed NamespaceDeclaration rather than assuming it","Fail fast at the caller: check string.IsNullOrEmpty(xmlNamespace) before constructing the map entry"],"exampleFix":"// before\nvar map = new NamespaceMapEntry(nsUri, asm, clrNs); // nsUri may be null\n// after\nif (nsUri == null)\n    throw new InvalidOperationException(\"xmlns declaration missing for prefix\");\nvar map = new NamespaceMapEntry(nsUri, asm, clrNs);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(xmlNamespace))\n    throw new ArgumentException(\"xmlNamespace must be a non-empty URI\");\nvar entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);","typeGuard":"bool CanBuildNamespaceMap(string xmlNamespace, string asm, string clrNs) =>\n    !string.IsNullOrEmpty(xmlNamespace) && !string.IsNullOrEmpty(asm) && !string.IsNullOrEmpty(clrNs);","tryCatchPattern":"try\n{\n    var entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);\n}\ncatch (ArgumentNullException ex)\n{\n    log.LogError(ex, \"Namespace map entry incomplete: {Param} is null\", ex.ParamName);\n}","preventionTips":["Verify xmlns declarations exist before creating map entries","Build map entries from parsed NamespaceDeclaration data, not raw strings","Validate all three arguments together in a helper before constructing"],"tags":["wpf","xaml","argument-null","namespace-map"],"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"}