{"record":{"id":"60d2951ab4088554","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-clrnamespace","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(clrNamespace));","messagePattern":"throw new ArgumentNullException\\(nameof\\(clrNamespace\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":4236,"sourceCode":"        {\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>\n        /// <param name=\"assemblyPath\">Path to use when loading assembly.  This may be null.</param>\n         internal NamespaceMapEntry(\n                string xmlNamespace,\n                string assemblyName,\n                string clrNamespace,\n                string assemblyPath) : this(xmlNamespace, assemblyName, clrNamespace)","sourceCodeStart":4218,"sourceCodeEnd":4254,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L4218-L4254","documentation":"XamlTypeMapper's MappingUri/PageColorMapper constructor (the internal mapper entry type) requires xmlNamespace, assemblyName, and clrNamespace to be non-null; each missing value throws ArgumentNullException. This library validates constructor inputs up front so the mapper never holds partially initialized namespace-to-assembly mappings, which would corrupt XAML type resolution later.","triggerScenarios":"Calling the XamlTypeMapper MappingUri constructor (e.g. new MappingUri(xmlNamespace, assemblyName, clrNamespace)) with a null clrNamespace string — typically because the namespace string came from an uninitialized variable or a dictionary lookup that returned null.","commonSituations":"Hand-building a XamlTypeMapper programmatically (custom designer tooling, unit tests) where the clrNamespace was read from config or reflection metadata that was missing; refactors that renamed a constant leaving null in one of the three mapping arguments.","solutions":["Ensure clrNamespace is a non-empty CLR namespace string (e.g. 'System.Windows.Controls') before constructing the mapping","If the namespace comes from reflection, verify the Type.Namespace value is not null (types in the global namespace return null)","If the mapping is optional, skip adding it instead of constructing with null"],"exampleFix":"// before\nvar mapping = new MappingUri(xmlNamespace, assemblyName, type.Namespace); // type.Namespace can be null\n// after\nif (string.IsNullOrEmpty(type.Namespace)) throw new InvalidOperationException($\"Type {type} has no namespace\");\nvar mapping = new MappingUri(xmlNamespace, assemblyName, type.Namespace);","handlingStrategy":"validation","validationCode":"if (xmlNamespace == null) throw new ArgumentException(\"xmlNamespace must not be null\");\nif (assemblyName == null) throw new ArgumentException(\"assemblyName must not be null\");\nif (clrNamespace == null) throw new ArgumentException(\"clrNamespace must not be null\");\nvar mapping = new MappingUri(xmlNamespace, assemblyName, clrNamespace);","typeGuard":"static bool HasClrNamespace(Type t) => !string.IsNullOrEmpty(t.Namespace);","tryCatchPattern":"try { var m = new MappingUri(ns, asm, clrNs); }\ncatch (ArgumentNullException ex) { Log.Error(ex, \"XamlTypeMapper mapping requires non-null arguments\"); throw; }","preventionTips":["Validate all three namespace/assembly strings before constructing mappings","Remember Type.Namespace is null for global-namespace types","Never pass reflection-derived strings without a null check"],"tags":["wpf","xaml","argument-null"],"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"}