dotnet/wpf · error · ArgumentNullException
Argument 'propertyName' cannot be null or empty.
Error message
Argument 'propertyName' cannot be null or empty.
What it means
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'.
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.
Example fix
// before
new PropertyMappingExceptionEventArgs(ex, currentProperty, value); // currentProperty may be ""
// after
if (!string.IsNullOrEmpty(currentProperty))
new PropertyMappingExceptionEventArgs(ex, currentProperty, value); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(propertyName))
throw new ArgumentException("propertyName required for mapping error args");
var args = new PropertyMappingExceptionEventArgs(ex, propertyName, value); Type guard
bool IsValidMappingProp(string prop) => !string.IsNullOrEmpty(prop);
Try / catch
try { var e = new PropertyMappingExceptionEventArgs(ex, prop, value); }
catch (ArgumentNullException) { log.Error($"Missing property name for error on value {value}"); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: Error-handling glue around PropertyMap where the property name variable is only set inside a try block; forwarding a TranslatorAppliedEventArgs property that was empty.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- The exception argument cannot be null.
- ArgumentNullException(nameof(assemblyNames))
- nameof(name)
- SR.EventArgIsNull
- anchorLocator.Parts
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/735fe7c52c6ae3e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMappingExceptionEventArgs.cs:28
/// </summary>
public class PropertyMappingExceptionEventArgs : IntegrationExceptionEventArgs
{
private string _propertyName;
private object _propertyValue;
/// <summary>
/// Initializes a new instance of the PropertyMappingExceptionEventArgs class.
/// </summary>
public PropertyMappingExceptionEventArgs(Exception exception, string propertyName, object propertyValue)
: base(false, exception)
{
if (exception == null)
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, "exception"));
}
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_ArgumentNullOrEmpty, "propertyName"));
}
_propertyName = propertyName;
_propertyValue = propertyValue;
}
/// <summary>
/// Identifies the property that was being mapped when the exception occurred.
/// </summary>
public string PropertyName
{
get
{
return _propertyName;
}
}
/// <summary>
/// Specifies the value of the property that was being mapped when the exception occurred.View on GitHub (pinned to 81131a70a4)