abpframework/abp · error · ArgumentException
{parameterName} has a default value!
Error message
{parameterName} has a default value! What it means
Thrown by Check.NotDefaultOrNull<T> when the nullable struct is non-null but its value equals default(T) (e.g. Guid.Empty, 0, DateTime.MinValue). It is the second guard in that method and exists because default values of structs are often semantically 'unset'. ArgumentException carries parameterName.
Source
Thrown at framework/src/Volo.Abp.Core/Volo/Abp/Check.cs:355
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
public static T NotDefaultOrNull<T>(
[System.Diagnostics.CodeAnalysis.NotNull] T? value,
[InvokerParameterName][NotNull] string parameterName)
where T : struct
{
if (value == null)
{
throw new ArgumentException($"{parameterName} is null!", parameterName);
}
if (value.Value.Equals(default(T)))
{
throw new ArgumentException($"{parameterName} has a default value!", parameterName);
}
return value.Value;
}
}
View on GitHub (pinned to 7ed43b1931)
Solutions
- Generate a real value (Guid.NewGuid()) or fetch the real id before calling NotDefaultOrNull.
- If default(T) is a legal value for your domain, use Check.NotNull on a boxed reference or a different guard instead.
- Set sensible non-default initializers on DTO properties (e.g. CreatedAt = Clock.Now).
- Reject default(T) at the API boundary so the caller is told the field is effectively unset.
Example fix
// before var id = Check.NotDefaultOrNull(entity.Id, nameof(entity.Id)); // after entity.Id = entity.Id == Guid.Empty ? Guid.NewGuid() : entity.Id; var id = Check.NotDefaultOrNull(entity.Id, nameof(entity.Id));
Defensive patterns
Strategy: validation
Validate before calling
static bool IsNotDefault<T>(T? value) where T : struct
=> value is not null && !value.Value.Equals(default(T));
if (!IsNotDefault(entity.Id)) return BadRequest("Id is empty/default"); Type guard
static bool IsMeaningful(Guid? id) => id is Guid g && g != Guid.Empty;
Try / catch
try
{
var id = Check.NotDefaultOrNull(entity.Id, nameof(entity.Id));
}
catch (ArgumentException ex) when (ex.ParamName == nameof(entity.Id))
{
return BadRequest(ex.Message);
} Prevention
- Generate Guid.NewGuid() at construction rather than relying on Guid.Empty.
- Treat default(struct) as 'unset' in your domain and reject it at the boundary.
- If default(T) is legitimate in your domain, do not use NotDefaultOrNull.
When it happens
Trigger: Calling Check.NotDefaultOrNull(value, nameof(value)) where value is Guid.Empty, 0, DateTime.MinValue, default(int), etc.
Common situations: A Guid id left as Guid.Empty by deserialization, a date defaulting to 0001-01-01, or an enum/int that was never assigned and read as 0.
Related errors
- {parameterName} is null!
- Given type ({item.AssemblyQualifiedName}) should be instance
- repositoryNameWithOrganization '{repositoryNameWithOrganizat
- Can not set {companyName} if {companyNamePlaceHolder} is nul
- len argument can not be bigger than given string's length!
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/6af452b85f10e0ce.
Report an issue: GitHub.