dotnet/wpf · error · ArgumentNullException
The translator argument cannot be null.
Error message
The translator argument cannot be null.
What it means
PropertyMap's translator setter validates the value: if translator is null it throws ArgumentNullException with SR.WFI_NullArgument ('The translator argument cannot be null.'). To remove a mapping use Remove or set via the underlying dictionary API semantics, not a null delegate — the setter only accepts a valid PropertyTranslator.
Solutions
- Call PropertyMap.Remove(propertyName) (or Reset) to clear a mapping instead of assigning null.
- Assign a no-op translator: (control, value) => { } if you need a mapping present but inert.
- Guard the assignment: if (translator != null) map[name] = translator;
- Check why the delegate is null — verify factory/initialization code paths return a real PropertyTranslator.
Example fix
// before
host.PropertyMap["Background"] = null; // throws
// after
host.PropertyMap.Remove("Background"); Defensive patterns
Strategy: type-guard
Validate before calling
if (translator != null)
host.PropertyMap[propertyName] = translator;
else
host.PropertyMap.Remove(propertyName); // null means 'remove', not 'assign null' Type guard
static bool CanAssignTranslator(PropertyTranslator translator) => translator is not null;
Try / catch
try
{
host.PropertyMap[propertyName] = translator;
}
catch (ArgumentNullException ex) when (ex.ParamName == "translator")
{
logger.LogError(ex, "Translator for '{Property}' was null; use Remove to clear", propertyName);
} Prevention
- To clear a mapping call PropertyMap.Remove(name), never assign null.
- Use a no-op delegate when a mapping must exist but do nothing: (c, v) => { }.
- Check delegate-producing factories for null-returning paths.
When it happens
Trigger: Assigning elementHost.PropertyMap["Background"] = null intending to 'clear' a translation; a delegate variable that failed to initialize; a factory method returning null that the caller assigns blindly.
Common situations: Developers assuming indexer assignment with null removes the mapping (it throws instead); conditional delegate creation where all branches returned null; deserialized translator delegates that were null.
Related errors
- The propertyName 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/2e46c58b369d95dd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs:86
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
{
get
{
return _wrappedDictionary.Keys;
}
}View on GitHub (pinned to 81131a70a4)