dotnetcore/CAP · error · ArgumentNullException
Value cannot be null. (Parameter 'configure')
Error message
Value cannot be null. (Parameter 'configure')
What it means
The UseAmazonSQS extension method registers an AmazonSQSOptionsExtension whose delegate configures the SQS options. Passing a null configure delegate would make the extension unusable, so the method throws ArgumentNullException immediately.
Solutions
- Pass a configuration lambda, even an empty one: options.UseAmazonSQS(opt => { ... })
- Use the convenience overload options.UseAmazonSQS("region") if only the region is needed
- Check that any variable holding the delegate is assigned before calling
- Wrap registration in try/catch and log the null delegate at startup
Example fix
// before
Action<AmazonSQSOptions>? configure = LoadConfigure(); // null
options.UseAmazonSQS(configure!);
// after
options.UseAmazonSQS(opt => { opt.Region = "us-east-1"; }); Defensive patterns
Strategy: validation
Validate before calling
if (configure is null) throw new InvalidOperationException("UseAmazonSQS requires a configure delegate"); Type guard
bool HasConfigure(Action<AmazonSQSOptions>? a) => a is not null;
Try / catch
try { options.UseAmazonSQS(configure); } catch (ArgumentNullException ex) when (ex.ParamName == "configure") { logger.LogError(ex, "SQS configure delegate was null"); throw; } Prevention
- Pass an explicit lambda inline rather than a delegate variable
- Prefer the convenience region overload when no advanced options are needed
When it happens
Trigger: Calling options.UseAmazonSQS(null) — e.g. the configure lambda is built dynamically or stored in a variable that is null, or using the overload with a region string and then chaining a null delegate.
Common situations: Configuration-driven CAP setup where the AWS options section is bound to an Action<AmazonSQSOptions> that is never assigned; refactoring that renamed a local method group leaving the delegate null.
Related errors
- Value cannot be null. (Parameter 'topicNames')
- Value cannot be null. (Parameter 'topics')
- Value cannot be null. (Parameter 'configure')
- Value cannot be null. (Parameter 'options')
- Value cannot be null. (Parameter 'topics')
AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14).
Data as JSON: /api/errors/aeb2eea3065b83eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/DotNetCore.CAP.AmazonSQS/CAP.Options.Extensions.cs:20
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using Amazon;
using DotNetCore.CAP;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection;
public static class CapOptionsExtensions
{
public static CapOptions UseAmazonSQS(this CapOptions options, RegionEndpoint region)
{
return options.UseAmazonSQS(opt => { opt.Region = region; });
}
public static CapOptions UseAmazonSQS(this CapOptions options, Action<AmazonSQSOptions> configure)
{
if (configure == null) throw new ArgumentNullException(nameof(configure));
options.RegisterExtension(new AmazonSQSOptionsExtension(configure));
return options;
}
}View on GitHub (pinned to e52b8508e5)