dotnetcore/CAP · error · ArgumentNullException
Value cannot be null. (Parameter 'configure')
Error message
Value cannot be null. (Parameter 'configure')
What it means
The delegate-based UseAzureServiceBus overload registers an AzureServiceBusOptionsExtension with the supplied configure action. A null delegate would leave the extension unable to configure anything, so ArgumentNullException is thrown up front.
Solutions
- Pass a real configuration lambda: options.UseAzureServiceBus(opt => opt.ConnectionString = cs)
- If only a connection string is needed, use the string overload UseAzureServiceBus(connectionString)
- Ensure the delegate variable is assigned before registration; assert with ArgumentNullException.ThrowIfNull in your own helper
- Remove the AddAzureServiceBus call entirely if Service Bus is not used, rather than calling it with null
Example fix
// before
Action<AzureServiceBusOptions>? cfg = BuildConfigurator(); // null
options.UseAzureServiceBus(cfg!);
// after
options.UseAzureServiceBus(opt =>
{
opt.ConnectionString = cs;
opt.AutoProvision = true;
}); Defensive patterns
Strategy: validation
Validate before calling
if (configure is null) throw new InvalidOperationException("UseAzureServiceBus requires a configure delegate"); Type guard
bool HasConfigure(Action<AzureServiceBusOptions>? a) => a is not null;
Try / catch
try { options.UseAzureServiceBus(configure); } catch (ArgumentNullException ex) when (ex.ParamName == "configure") { logger.LogError(ex, "ASB configure delegate was null"); throw; } Prevention
- Pass inline lambdas instead of delegate variables
- Prefer the string overload when only a connection string is needed
When it happens
Trigger: Calling options.UseAzureServiceBus((Action<AzureServiceBusOptions>)null) — e.g. a delegate variable loaded from a factory/config hook that returned null, or a generic helper that passes the action through without initializing it.
Common situations: Convention-based startup helpers that resolve the configure callback from DI and get null; test setup that passes a placeholder null action; refactors that removed the lambda but kept the call.
Related errors
- Value cannot be null. (Parameter 'configure')
- Value cannot be null. (Parameter 'options')
- Value cannot be null. (Parameter 'topics')
- Value cannot be null. (Parameter 'connectionString')
- Value cannot be null. (Parameter 'topicNames')
AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14).
Data as JSON: /api/errors/cae0050d0272cbbb.
Report an issue: GitHub.
Appendix: source
Thrown at src/DotNetCore.CAP.AzureServiceBus/CAP.Options.Extensions.cs:31
/// Configuration to use Azure Service Bus in CAP.
/// </summary>
/// <param name="options">CAP configuration options</param>
/// <param name="connectionString">Connection string for namespace or the entity.</param>
public static CapOptions UseAzureServiceBus(this CapOptions options, string connectionString)
{
if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));
return options.UseAzureServiceBus(opt => { opt.ConnectionString = connectionString; });
}
/// <summary>
/// Configuration to use Azure Service Bus in CAP.
/// </summary>
/// <param name="options">CAP configuration options</param>
/// <param name="configure">Provides programmatic configuration for the Azure Service Bus.</param>
public static CapOptions UseAzureServiceBus(this CapOptions options, Action<AzureServiceBusOptions> configure)
{
if (configure == null) throw new ArgumentNullException(nameof(configure));
options.RegisterExtension(new AzureServiceBusOptionsExtension(configure));
return options;
}
}View on GitHub (pinned to e52b8508e5)