HandyOrg/HandyControl · error · ArgumentNullException

The parameter can not be either null or empty or consist…

Error message

The parameter can not be either null or empty or consist only of white space characters.

What it means

Verify.IsNeitherNullNorWhitespace guards required string parameters: it throws ArgumentNullException for null and ArgumentException for strings that are empty or contain only whitespace ("" == value.Trim()).

Solutions

  1. Supply a non-null, non-whitespace string
  2. Initialize defaults before invoking the API
  3. Validate at the boundary with string.IsNullOrWhiteSpace for clearer messages
  4. Catch ArgumentNullException to identify the offending parameter

Example fix

// before
Verify.IsNeitherNullNorWhitespace(appUserModelId, "appUserModelId"); // NRE-style ArgumentNullException if null
// after
appUserModelId ??= "MyApp.Default";
Verify.IsNeitherNullNorWhitespace(appUserModelId, "appUserModelId");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(value))
    throw new ArgumentException($"'{name}' must be a non-blank string.", name);

Type guard

static bool IsNonBlankString(string s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try { Verify.IsNeitherNullNorWhitespace(value, name); }
catch (ArgumentNullException ex) { Log.Warn($"Parameter {name} was null", ex); }

Prevention

When it happens

Trigger: Calling Verify.IsNeitherNullNorWhitespace(null, name) — the null branch of the guard, typically from an API validating a required string like a path or name.

Common situations: Uninitialized string fields, missing registry/config values passed straight into shell APIs.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/870ef22b860b5481. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs:44

    {
        if (value == null)
        {
            throw new ArgumentNullException(name, "The parameter can not be either null or empty.");
        }
        if ("" == value)
        {
            throw new ArgumentException("The parameter can not be either null or empty.", name);
        }
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    [SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")]
    [DebuggerStepThrough]
    public static void IsNeitherNullNorWhitespace(string value, string name)
    {
        if (value == null)
        {
            throw new ArgumentNullException(name, "The parameter can not be either null or empty or consist only of white space characters.");
        }
        if ("" == value.Trim())
        {
            throw new ArgumentException("The parameter can not be either null or empty or consist only of white space characters.", name);
        }
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    [DebuggerStepThrough]
    public static void IsNotDefault<T>(T obj, string name) where T : struct
    {
        T t = default(T);
        if (t.Equals(obj))
        {
            throw new ArgumentException("The parameter must not be the default value.", name);
        }
    }

View on GitHub (pinned to 2c0875ebd6)