{"record":{"id":"2154e448dcee615b","repo":"dotnet/wpf","slug":"the-propertyname-argument-cannot-be-null","errorCode":null,"errorMessage":"The propertyName argument cannot be null.","messagePattern":"The propertyName argument cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs","lineNumber":82,"sourceCode":"        public PropertyTranslator this[String propertyName]\n        {\n            get\n            {\n                ThrowIfPropertyDoesntExistOnSource(propertyName);\n                PropertyTranslator value;\n                if (_wrappedDictionary.TryGetValue(propertyName, out value))\n                {\n                    return value;\n                }\n                return null;\n            }\n            set\n            {\n                //Run through our regular invalid property checks, then\n                //apply the translator\n                if (string.IsNullOrEmpty(propertyName))\n                {\n                    throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"propertyName\"));\n                }\n                if (value == null)\n                {\n                    throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"translator\"));\n                }\n                ThrowIfPropertyDoesntExistOnSource(propertyName);\n                _wrappedDictionary[propertyName] = value;    //This will replace an existing mapping, unlike Add.\n                Apply(propertyName);\n            }\n        }\n\n        /// <summary>\n        ///     Returns an ICollection of strings identifying all of the host control \n        ///     properties that have been mapped.  \n        /// </summary>\n        public ICollection Keys\n        {\n            get","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs#L64-L100","documentation":"PropertyMap's translator setter (this[propertyName] indexer) validates that propertyName is not null or empty before applying the translator, throwing ArgumentNullException with SR.WFI_NullArgument ('The propertyName argument cannot be null.'). Property mapping keys must be real property names on the host control, so an empty key is rejected up front.","triggerScenarios":"Assigning elementHost.PropertyMap[null] = translator or [\"\"] = translator; computing the property name from a variable that is null/empty (e.g. from reflection returning null, or uninitialized config).","commonSituations":"Dynamic property-name lists built from settings or resource files where entries are missing; string.Split producing empty tokens used as keys; loops over metadata where a name field is blank.","solutions":["Ensure the property name string is non-null and non-empty before indexing PropertyMap.","Skip or log empty entries when iterating a dynamic list of property names.","Use nameof() or verified property metadata to build names instead of user/config strings.","Note a null translator value is rejected separately (error 5318); fix both when populating maps from data."],"exampleFix":"// before\nmap[entry.Name] = translator; // entry.Name may be null/empty\n// after\nif (!string.IsNullOrEmpty(entry.Name))\n{\n    map[entry.Name] = translator;\n}","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(propertyName))\n{\n    host.PropertyMap[propertyName] = translator;\n}\nelse\n{\n    logger.LogWarning(\"Skipped property mapping with empty name\");\n}","typeGuard":"static bool IsValidPropertyName(string name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":"try\n{\n    host.PropertyMap[propertyName] = translator;\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"propertyName\")\n{\n    logger.LogError(ex, \"Cannot map property: name is null or empty\");\n}","preventionTips":["Sanitize dynamic property-name lists (filter null/empty entries before mapping).","Prefer nameof() over strings from config where possible.","Log-and-skip blank entries when iterating metadata-driven mappings."],"tags":["wpf","winforms-integration","propertymap","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}