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
- Pass a non-null, non-empty string.
- If whitespace should also fail, switch to Check.NotNullOrWhiteSpace instead.
- 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
- Resolve empty/null to a default at the caller before guarded APIs.
- Choose NotNullOrWhiteSpace instead when whitespace must also fail.
- Use [Required] on DTO properties so model binding rejects empty before your code runs.
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
- repositoryNameWithOrganization '{repositoryNameWithOrganizat
- Can not set {companyName} if {companyNamePlaceHolder} is nul
- {parameterName} can not be null!
- {parameterName} length must be equal to or lower than {maxLe
- {parameterName} length must be equal to or bigger than {minL
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/03950f078b01829f.
Report an issue: GitHub.