dotnet/orleans · error · ArgumentOutOfRangeException
count
Error message
count
What it means
Thrown by SQSStorage.GetMessages when the requested count is less than 1. SQS ReceiveMessage requires at least one message per call, so the provider rejects zero or negative counts up front rather than forwarding an invalid MaxNumberOfMessages to AWS.
Source
Thrown at src/AWS/Orleans.Streaming.SQS/Storage/SQSStorage.cs:193
{
ReportErrorAndRethrow(exc, "AddMessage");
}
}
/// <summary>
/// Get Messages from SQS Queue.
/// </summary>
/// <param name="count">The number of messages to peak. Min 1 and max 10</param>
/// <returns>Collection with messages from the queue</returns>
public async Task<IEnumerable<SQSMessage>> GetMessages(int count = 1)
{
try
{
if (string.IsNullOrWhiteSpace(queueUrl))
throw new InvalidOperationException("Queue not initialized");
if (count < 1)
throw new ArgumentOutOfRangeException(nameof(count));
var request = new ReceiveMessageRequest { QueueUrl = queueUrl, MaxNumberOfMessages = count <= MAX_NUMBER_OF_MESSAGE_TO_PEEK ? count : MAX_NUMBER_OF_MESSAGE_TO_PEEK };
var response = await sqsClient.ReceiveMessageAsync(request);
return response.Messages;
}
catch (Exception exc)
{
ReportErrorAndRethrow(exc, "GetMessages");
}
throw new InvalidOperationException("Unable to retrieve messages from the queue.");
}
/// <summary>
/// Delete a message from SQS queue
/// </summary>
/// <param name="message">The message to be deleted</param>
/// <returns></returns>
public async Task DeleteMessage(SQSMessage message)View on GitHub (pinned to fca799fa70)
Solutions
- Pass a count >= 1; use the method default of 1 when you have no specific batch size.
- Clamp the computed count: var take = Math.Max(1, requested); before calling GetMessages.
- Audit SQSAdapterReceiver/configuration for any code path that can supply 0.
- If 0 legitimately means 'nothing to do', short-circuit before calling GetMessages.
Example fix
// before var msgs = await storage.GetMessages(remaining); // remaining == 0 -> throws // after if (remaining < 1) return Enumerable.Empty<SQSMessage>(); var msgs = await storage.GetMessages(remaining);
Defensive patterns
Strategy: validation
Validate before calling
if (count < 1) throw new ArgumentOutOfRangeException(nameof(count), count, "must be >= 1"); var take = Math.Min(count, SQSStorage.MAX_NUMBER_OF_MESSAGE_TO_PEEK); return await storage.GetMessages(take);
Try / catch
try { return await storage.GetMessages(clamped); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "count")
{
logger.LogDebug("GetMessages called with count {Count}; clamping to 1.", count);
return await storage.GetMessages(1);
} Prevention
- Clamp computed batch sizes with Math.Max(1, value).
- Short-circuit reads when the requested count is legitimately 0.
- Treat 0 as a no-op at the caller, never forward it to GetMessages.
When it happens
Trigger: Calling GetMessages(0), GetMessages(-1), or passing a computed/loop variable that underflows to <= 0. SQSAdapterReceiver paths that derive count from configuration or backpressure could feed 0 when the queue is idle.
Common situations: Passing an unconfigured option (default int 0) as the count; arithmetic that subtracts batch sizes and yields a negative remainder; porting code that treated 0 as 'use default' (the default is 1, so 0 must be passed explicitly).
Related errors
- message
- ReceiptHandle
- queueId
- Message contains no events
- Error doing {operation} for SQS queue {QueueName}
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/80d82c7c383b4f66.
Report an issue: GitHub.