abpframework/abp · error · ArgumentException

{parameterName} can not be null or empty!

Error message

{parameterName} can not be null or empty!

What it means

Check.NotNullOrEmpty(string) rejects null or empty ("") strings using IsNullOrEmpty() but ALLOWS whitespace-only values (less strict than NotNullOrWhiteSpace). After the emptiness check it applies optional maxLength/minLength bounds. Choose this when a literal empty is invalid but whitespace is acceptable.

Source

Thrown at framework/src/Volo.Abp.Core/Volo/Abp/Check.cs:97

        if (minLength > 0 && value!.Length < minLength)
        {
            throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
        }

        return value;
    }

    [ContractAnnotation("value:null => halt")]
    public static string NotNullOrEmpty(
        [System.Diagnostics.CodeAnalysis.NotNull] string? value,
        [InvokerParameterName][NotNull] string parameterName,
        int maxLength = int.MaxValue,
        int minLength = 0)
    {
        if (value.IsNullOrEmpty())
        {
            throw new ArgumentException($"{parameterName} can not be null or empty!", parameterName);
        }

        if (value!.Length > maxLength)
        {
            throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName);
        }

        if (minLength > 0 && value!.Length < minLength)
        {
            throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName);
        }

        return value;
    }

    [ContractAnnotation("value:null => halt")]
    public static ICollection<T> NotNullOrEmpty<T>(
        [System.Diagnostics.CodeAnalysis.NotNull] ICollection<T>? value,

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Pass a non-null, non-empty string.
  2. If whitespace should also fail, switch to Check.NotNullOrWhiteSpace instead.
  3. Default-fall to a real value at the caller if empty is a legitimate 'unset' state.

Example fix

// before
Check.NotNullOrEmpty("", nameof(x)); // throws

// after
Check.NotNullOrEmpty(value ?? "default", nameof(x));
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(value))
    value = fallback;
Check.NotNullOrEmpty(value, nameof(value));

Type guard

bool IsNonEmpty(string? s) => !string.IsNullOrEmpty(s);

Prevention

When it happens

Trigger: Check.NotNullOrEmpty("", nameof(x)) or null; an ABP API that requires a non-empty value receiving an empty string.

Common situations: An identifier that may be " " but not ""; config values that must be set (non-empty) but where whitespace is tolerated; mis-pick of validator (should have used NotNullOrWhiteSpace).

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/03950f078b01829f. Report an issue: GitHub.