dotnetcore/CAP · error · ArgumentException
Delay time span must be greater than 0 (Parameter…
Error message
Delay time span must be greater than 0 (Parameter 'delayTime')
What it means
An argument guard in the default ICapPublisher's PublishDelayAsync: the delayTime TimeSpan passed by the caller must represent a positive delay. Passing zero, a negative TimeSpan, or a default(TimeSpan) makes delayed publishing meaningless (it would be an immediate publish), so ArgumentException fires before any message is enqueued.
Solutions
- Pass a positive TimeSpan, e.g. await publisher.PublishDelayAsync(TimeSpan.FromMinutes(5), "order.created", payload).
- When delay is computed dynamically, guard it first: if (delay <= TimeSpan.Zero) use PublishAsync instead of PublishDelayAsync.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs:75 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14).
Data as JSON: /api/errors/b96db367a5ed51af.
Report an issue: GitHub.
Appendix: source
Thrown at src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs:75
await PublishInternalAsync(name, value, headers, null, cancellationToken).ConfigureAwait(false);
}
public async Task PublishAsync<T>(string name, T? value, string? callbackName = null,
CancellationToken cancellationToken = default)
{
var headers = new Dictionary<string, string?>
{
{ Headers.CallbackName, callbackName }
};
await PublishAsync(name, value, headers, cancellationToken).ConfigureAwait(false);
}
public async Task PublishDelayAsync<T>(TimeSpan delayTime, string name, T? value, IDictionary<string, string?> headers,
CancellationToken cancellationToken = default)
{
if (delayTime <= TimeSpan.Zero)
{
throw new ArgumentException("Delay time span must be greater than 0", nameof(delayTime));
}
await PublishInternalAsync(name, value, headers, delayTime, cancellationToken).ConfigureAwait(false);
}
public async Task PublishDelayAsync<T>(TimeSpan delayTime, string name, T? value, string? callbackName = null,
CancellationToken cancellationToken = default)
{
var header = new Dictionary<string, string?>
{
{ Headers.CallbackName, callbackName }
};
await PublishDelayAsync(delayTime, name, value, header, cancellationToken).ConfigureAwait(false);
}
public void Publish<T>(string name, T? value, string? callbackName = null)
{View on GitHub (pinned to e52b8508e5)