{"record":{"id":"735fe7c52c6ae3e7","repo":"dotnet/wpf","slug":"argument-propertyname-cannot-be-null-or-empty-735fe7","errorCode":null,"errorMessage":"Argument 'propertyName' cannot be null or empty.","messagePattern":"Argument 'propertyName' cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMappingExceptionEventArgs.cs","lineNumber":28,"sourceCode":"    /// </summary>\n    public class PropertyMappingExceptionEventArgs : IntegrationExceptionEventArgs \n    {\n        private string _propertyName;\n        private object _propertyValue;\n\n        /// <summary>\n        /// Initializes a new instance of the PropertyMappingExceptionEventArgs class.\n        /// </summary>\n        public PropertyMappingExceptionEventArgs(Exception exception, string propertyName, object propertyValue) \n            : base(false, exception)\n        {\n            if (exception == null)\n            {\n                throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"exception\"));\n            }\n            if (string.IsNullOrEmpty(propertyName))\n            {\n                throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_ArgumentNullOrEmpty, \"propertyName\"));\n            }\n            _propertyName = propertyName;\n            _propertyValue = propertyValue;\n        }\n\n        /// <summary>\n        /// Identifies the property that was being mapped when the exception occurred.\n        /// </summary>\n        public string PropertyName\n        {\n            get\n            {\n                return _propertyName;\n            }\n        }\n\n        /// <summary>\n        /// Specifies the value of the property that was being mapped when the exception occurred.","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMappingExceptionEventArgs.cs#L10-L46","documentation":"Besides the exception, PropertyMappingExceptionEventArgs requires the name of the property whose mapping failed. An empty or null propertyName cannot identify the failing mapping, so the constructor throws ArgumentNullException naming 'propertyName'.","triggerScenarios":"Constructing PropertyMappingExceptionEventArgs(ex, null, value) or (ex, \"\", value) when the caller lost track of which property was being translated (e.g. in a generic loop over mapped properties).","commonSituations":"Error-handling glue around PropertyMap where the property name variable is only set inside a try block; forwarding a TranslatorAppliedEventArgs property that was empty.","solutions":["Pass the actual non-empty property name from the translation context.","Guard: if (!string.IsNullOrEmpty(propName)) new PropertyMappingExceptionEventArgs(ex, propName, value);","Ensure the loop/handler carries the property name through to the event-args construction."],"exampleFix":"// before\nnew PropertyMappingExceptionEventArgs(ex, currentProperty, value); // currentProperty may be \"\"\n// after\nif (!string.IsNullOrEmpty(currentProperty))\n    new PropertyMappingExceptionEventArgs(ex, currentProperty, value);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(propertyName))\n    throw new ArgumentException(\"propertyName required for mapping error args\");\nvar args = new PropertyMappingExceptionEventArgs(ex, propertyName, value);","typeGuard":"bool IsValidMappingProp(string prop) => !string.IsNullOrEmpty(prop);","tryCatchPattern":"try { var e = new PropertyMappingExceptionEventArgs(ex, prop, value); }\ncatch (ArgumentNullException) { log.Error($\"Missing property name for error on value {value}\"); }","preventionTips":["Thread the property name through the translation loop into error handling","Validate the name variable at loop entry, not at event-args construction","Default to the PropertyMap.PropertyMappingExceptionEventArgs.PropertyName source when available"],"tags":["argument-null","empty-string","event-args","constructor"],"backgroundTag":"empty-required-field","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"}