dotnet/wpf · error · ArgumentNullException

The parameter can not be either null or empty.

Error message

The parameter can not be either null or empty.

What it means

Verify.IsNeitherNullNorEmpty validates that a string argument is neither null nor the empty string. It throws ArgumentNullException (null) or ArgumentException (empty) with the supplied parameter name. This is a preconditions helper used by WPF's internal Standard utility library to fail fast on bad string arguments.

Solutions

  1. Check String.IsNullOrEmpty(value) before the call and supply a valid non-empty string.
  2. If the value legitimately can be empty, stop calling the Verify API with it or provide a sensible fallback string.
  3. If it is a parameter name argument, make sure you actually pass nameof(param), not an empty literal.
  4. Trace which argument is null/empty from the exception's ParamName property and fix at the source.

Example fix

// before
Verify.IsNeitherNullNorEmpty(name, nameof(name)); // name may be ""
// after
if (string.IsNullOrEmpty(name)) name = "<unnamed>";
Verify.IsNeitherNullNorEmpty(name, nameof(name));
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(value))
    throw new ArgumentException($"{nameof(value)} must be non-null and non-empty", nameof(value));
Verify.IsNeitherNullNorEmpty(value, nameof(value));

Type guard

static bool IsNonEmptyString(string s) => !string.IsNullOrEmpty(s);

Try / catch

try {
    Verify.IsNeitherNullNorEmpty(value, nameof(value));
} catch (ArgumentNullException ex) {
    log.Error($"Parameter {ex.ParamName} was null");
} catch (ArgumentException ex) {
    log.Error($"Parameter {ex.ParamName} was empty");
}

Prevention

When it happens

Trigger: Calling any API that routes through Verify.IsNeitherNullNorEmpty (e.g. Verify.IsNeitherNullNorEmpty directly, or internal WPF helpers like HttpUtility/property-name checks) passing a null string: ArgumentNullException is thrown at Verify.cs:62; passing "": ArgumentException at Verify.cs:66.

Common situations: Passing string.Empty as a parameter name or resource key to WPF helper APIs; deserialization producing empty strings; refactoring that removed a default value previously supplied.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:62

        }

        /// <summary>
        /// Ensure that an argument is neither null nor empty.
        /// </summary>
        /// <param name="value">The string to validate.</param>
        /// <param name="name">The name of the parameter that will be presented if an exception is thrown.</param>    
        [SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")]
        [DebuggerStepThrough]
        public static void IsNeitherNullNorEmpty(string value, string name)
        {
            // catch caller errors, mixing up the parameters.  Name should never be empty.
            Assert.IsNeitherNullNorEmpty(name);

            // Notice that ArgumentNullException and ArgumentException take the parameters in opposite order :P
            const string errorMessage = "The parameter can not be either null or empty.";
            if (null == value)
            {
                throw new ArgumentNullException(name, errorMessage);
            }
            if ("" == value)
            {
                throw new ArgumentException(errorMessage, name);
            }
        }

        /// <summary>
        /// Ensure that an argument is neither null nor does it consist only of whitespace.
        /// </summary>
        /// <param name="value">The string to validate.</param>
        /// <param name="name">The name of the parameter that will be presented if an exception is thrown.</param>        
        [SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")]
        [DebuggerStepThrough]
        public static void IsNeitherNullNorWhitespace(string value, string name)
        {
            // catch caller errors, mixing up the parameters.  Name should never be empty.
            Assert.IsNeitherNullNorEmpty(name);

View on GitHub (pinned to 81131a70a4)