dotnet/wpf · error · ArgumentNullException
The propertyName argument cannot be null.
Error message
The propertyName argument cannot be null.
What it means
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.
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.
Example fix
// before
map[entry.Name] = translator; // entry.Name may be null/empty
// after
if (!string.IsNullOrEmpty(entry.Name))
{
map[entry.Name] = translator;
} Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(propertyName))
{
host.PropertyMap[propertyName] = translator;
}
else
{
logger.LogWarning("Skipped property mapping with empty name");
} Type guard
static bool IsValidPropertyName(string name) => !string.IsNullOrWhiteSpace(name);
Try / catch
try
{
host.PropertyMap[propertyName] = translator;
}
catch (ArgumentNullException ex) when (ex.ParamName == "propertyName")
{
logger.LogError(ex, "Cannot map property: name is null or empty");
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- The translator argument cannot be null.
- A property mapping with the same name already exists.
- The exception argument cannot be null.
- annotation component
- ArgumentNullException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2154e448dcee615b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs:82
public PropertyTranslator this[String propertyName]
{
get
{
ThrowIfPropertyDoesntExistOnSource(propertyName);
PropertyTranslator value;
if (_wrappedDictionary.TryGetValue(propertyName, out value))
{
return value;
}
return null;
}
set
{
//Run through our regular invalid property checks, then
//apply the translator
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, "propertyName"));
}
if (value == null)
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, "translator"));
}
ThrowIfPropertyDoesntExistOnSource(propertyName);
_wrappedDictionary[propertyName] = value; //This will replace an existing mapping, unlike Add.
Apply(propertyName);
}
}
/// <summary>
/// Returns an ICollection of strings identifying all of the host control
/// properties that have been mapped.
/// </summary>
public ICollection Keys
{
getView on GitHub (pinned to 81131a70a4)