{"record":{"id":"e1b974d904fe84c8","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-value","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(value));","messagePattern":"throw new ArgumentNullException\\(nameof\\(value\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":4274,"sourceCode":"            _assemblyPath = assemblyPath;\n        }\n\n        #endregion Constructors\n\n\n        #region Properties\n\n        /// <summary>\n        /// Xml namespace specified in the constructor\n        /// </summary>\n        public string XmlNamespace\n        {\n            get { return _xmlNamespace; }\n            set\n            {\n                if (value == null)\n                {\n                    throw new ArgumentNullException(nameof(value));\n                }\n                if (_xmlNamespace == null)\n                {\n                    _xmlNamespace = value;\n                }\n            }\n        }\n\n        /// <summary>\n        /// AssemblyName specified in the constructor\n        /// </summary>\n        public string AssemblyName\n        {\n            get { return _assemblyName; }\n            set\n            {\n                if (value == null)\n                {","sourceCodeStart":4256,"sourceCodeEnd":4292,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L4256-L4292","documentation":"The XmlNamespace property setter on XamlTypeMapper's mapping entry type rejects null values with ArgumentNullException. The setter is write-once: it only assigns the backing field when it is still null, but null values are rejected outright to keep the namespace mapping well-formed.","triggerScenarios":"Assigning null to the XmlNamespace property of a XamlTypeMapper mapping entry (e.g. mapper.XmlNamespace = someString) where someString is null.","commonSituations":"Deserialization or config parsing that produced a null namespace string; test code probing the setter's behavior.","solutions":["Assign a non-null namespace string (e.g. 'http://schemas.microsoft.com/winfx/2006/xaml/presentation')","Guard with string.IsNullOrEmpty before assignment","If clearing the mapping is intended, replace the whole mapping object instead of nulling a property"],"exampleFix":"// before\nentry.XmlNamespace = config.XmlNamespace; // may be null\n// after\nif (config.XmlNamespace != null) entry.XmlNamespace = config.XmlNamespace;","handlingStrategy":"validation","validationCode":"if (ns != null) entry.XmlNamespace = ns;","typeGuard":"static bool IsValidNamespace(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try { entry.XmlNamespace = value; }\ncatch (ArgumentNullException ex) { Log.Warn(\"XmlNamespace cannot be null: \" + ex.Message); }","preventionTips":["Check config/deserialized namespace strings for null before assignment","Use string.Empty for default namespaces rather than null"],"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"}