dotnet/wpf · error · ArgumentNullException

Argument 'propertyName' cannot be null or empty.

Error message

Argument 'propertyName' cannot be null or empty.

What it means

PropertyMap.Reset validates that the propertyName argument is a non-empty string before removing the custom translator and restoring the default one. A null or empty name cannot match any mapped property, so the method throws ArgumentNullException immediately.

Solutions

  1. Pass the exact non-empty property name, e.g. propertyMap.Reset("Background").
  2. Guard the call: if (!string.IsNullOrEmpty(name)) propertyMap.Reset(name);
  3. Fix the source of the empty string (uninitialized variable, config key).

Example fix

// before
propertyMap.Reset(propertyName); // propertyName may be ""
// after
if (!string.IsNullOrEmpty(propertyName))
{
    propertyMap.Reset(propertyName);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(propertyName))
    return; // or throw your own descriptive error
propertyMap.Reset(propertyName);

Type guard

bool IsValidPropertyName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { propertyMap.Reset(name); }
catch (ArgumentNullException ex) { log.Warn("Reset skipped: empty property name", ex); }

Prevention

When it happens

Trigger: Calling propertyMap.Reset(null) or propertyMap.Reset("") from code that clears translators dynamically, e.g. looping over a dictionary of overrides where the key was never initialized.

Common situations: Resetting all custom translations in a loop driven by a config or UI binding where a key is empty; calling Reset before any property name is assigned from deserialized configuration.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/223dcce9ea7d2822. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs:250

        /// <summary>
        ///     Translator for individual property
        /// </summary>
        internal void EmptyPropertyTranslator(object host, string propertyName, object value)
        {
        }



        /// <summary>
        ///     Restores the default property mapping for the specified property.
        /// </summary>
        /// <param name="propertyName">A string containing the name of the host control property.</param>
        public void Reset(String propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_ArgumentNullOrEmpty, "propertyName"));
            }

            //Resetting means get the value from the list of default values,
            //if it's there, otherwise removing the item you've added.
            PropertyTranslator value;
            if (DefaultTranslators.TryGetValue(propertyName, out value))
            {
                this[propertyName] = value;
            }
            else
            {
                Remove(propertyName);
            }
        }

        /// <summary>
        ///     Restores the default property mapping for all of the host control's properties.
        /// </summary>

View on GitHub (pinned to 81131a70a4)