HangfireIO/Hangfire · error · ArgumentOutOfRangeException
The Order value should be greater or equal to '-1'
Error message
The Order value should be greater or equal to '-1'
What it means
JobFilterAttribute.Order controls filter execution precedence. The setter at JobFilterAttribute.cs:46 enforces a floor of JobFilter.DefaultOrder (which is -1, the value filters get when no explicit order is set). Any value below -1 is rejected because it would place a filter before the framework's own default-priority filters, producing undefined execution semantics.
Source
Thrown at src/Hangfire.Core/Common/JobFilterAttribute.cs:46
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method)]
public abstract class JobFilterAttribute : Attribute, IJobFilter
{
private static readonly ConcurrentDictionary<Type, bool> MultiuseAttributeCache = new ConcurrentDictionary<Type, bool>();
private int _order = JobFilter.DefaultOrder;
[JsonIgnore]
public bool AllowMultiple => AllowsMultiple(GetType());
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[DefaultValue(JobFilter.DefaultOrder)]
public int Order
{
get { return _order; }
set
{
if (value < JobFilter.DefaultOrder)
{
throw new ArgumentOutOfRangeException(nameof(value), "The Order value should be greater or equal to '-1'");
}
_order = value;
}
}
#if !NETSTANDARD1_3
[JsonIgnore]
public override object TypeId => base.TypeId;
#endif
private static bool AllowsMultiple(Type attributeType)
{
return MultiuseAttributeCache.GetOrAdd(
attributeType,
static type => type.GetTypeInfo()
.GetCustomAttributes<AttributeUsageAttribute>(inherit: true)
.First()
.AllowMultiple);View on GitHub (pinned to c236dd0f93)
Solutions
- Set Order to a value >= -1 (use 0 or higher for custom filters).
- If you need the earliest execution, use Order = -1 (JobFilter.DefaultOrder).
- Validate configuration-sourced Order values before assignment if they come from external config.
Example fix
// before attr.Order = -10; // after attr.Order = 0;
Defensive patterns
Strategy: validation
Validate before calling
const int MinOrder = -1; // JobFilter.DefaultOrder
if (configuredOrder < MinOrder)
throw new ArgumentOutOfRangeException(nameof(configuredOrder),
$"Order must be >= {MinOrder}.");
attr.Order = configuredOrder; Prevention
- Treat -1 as the lowest valid Order value.
- Validate externally-sourced Order values (config, JSON) before assignment.
- Prefer non-negative Order values for custom filters.
When it happens
Trigger: Explicitly assigning a negative value less than -1 to the Order property of any JobFilterAttribute subclass, e.g. attr.Order = -5; or myFilter.Order = int.MinValue.
Common situations: Trying to force a filter to run before everything else by using an arbitrarily negative number; copying a pattern from another DI framework that allows any int; deserializing filter config from JSON with an out-of-range value.
Related errors
- Attempts value must be equal or greater than zero.
- DelaysInSeconds value must be an array of non-negative numbe
- client
- storage
- options
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/759af7959dbfd060.
Report an issue: GitHub.