{"record":{"id":"cae0050d0272cbbb","repo":"dotnetcore/CAP","slug":"value-cannot-be-null-parameter-configure-cap-options","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'configure')","messagePattern":"Value cannot be null\\. \\(Parameter 'configure'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.AzureServiceBus/CAP.Options.Extensions.cs","lineNumber":31,"sourceCode":"    /// Configuration to use Azure Service Bus in CAP.\n    /// </summary>\n    /// <param name=\"options\">CAP configuration options</param>\n    /// <param name=\"connectionString\">Connection string for namespace or the entity.</param>\n    public static CapOptions UseAzureServiceBus(this CapOptions options, string connectionString)\n    {\n        if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));\n\n        return options.UseAzureServiceBus(opt => { opt.ConnectionString = connectionString; });\n    }\n\n    /// <summary>\n    /// Configuration to use Azure Service Bus in CAP.\n    /// </summary>\n    /// <param name=\"options\">CAP configuration options</param>\n    /// <param name=\"configure\">Provides programmatic configuration for the Azure Service Bus.</param>\n    public static CapOptions UseAzureServiceBus(this CapOptions options, Action<AzureServiceBusOptions> configure)\n    {\n        if (configure == null) throw new ArgumentNullException(nameof(configure));\n\n        options.RegisterExtension(new AzureServiceBusOptionsExtension(configure));\n\n        return options;\n    }\n}","sourceCodeStart":13,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.AzureServiceBus/CAP.Options.Extensions.cs#L13-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nAction<AzureServiceBusOptions>? cfg = BuildConfigurator(); // null\noptions.UseAzureServiceBus(cfg!);\n// after\noptions.UseAzureServiceBus(opt =>\n{\n    opt.ConnectionString = cs;\n    opt.AutoProvision = true;\n});","handlingStrategy":"validation","validationCode":"if (configure is null) throw new InvalidOperationException(\"UseAzureServiceBus requires a configure delegate\");","typeGuard":"bool HasConfigure(Action<AzureServiceBusOptions>? a) => a is not null;","tryCatchPattern":"try { options.UseAzureServiceBus(configure); } catch (ArgumentNullException ex) when (ex.ParamName == \"configure\") { logger.LogError(ex, \"ASB configure delegate was null\"); throw; }","preventionTips":["Pass inline lambdas instead of delegate variables","Prefer the string overload when only a connection string is needed"],"tags":["dotnet","azure-service-bus","null-argument","configuration-extension"],"backgroundTag":"null-argument","analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}