{"record":{"id":"418d1a53e5762c10","repo":"dotnetcore/CAP","slug":"value-cannot-be-null-parameter-topics-418d1a","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'topics')","messagePattern":"Value cannot be null\\. \\(Parameter 'topics'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.AzureServiceBus/AzureServiceBusConsumerClient.cs","lineNumber":56,"sourceCode":"        IServiceProvider serviceProvider)\n    {\n        _logger = logger;\n        _subscriptionName = subscriptionName;\n        _groupConcurrent = groupConcurrent;\n        _semaphore = new SemaphoreSlim(groupConcurrent);\n        _serviceProvider = serviceProvider;\n        _asbOptions = options.Value ?? throw new ArgumentNullException(nameof(options));\n    }\n\n    public Func<TransportMessage, object?, Task>? OnMessageCallback { get; set; }\n\n    public Action<LogMessageEventArgs>? OnLogCallback { get; set; }\n\n    public BrokerAddress BrokerAddress => ServiceBusHelpers.GetBrokerAddress(_asbOptions.ConnectionString, _asbOptions.Namespace);\n\n    public async Task SubscribeAsync(IEnumerable<string> topics)\n    {\n        if (topics == null) throw new ArgumentNullException(nameof(topics));\n\n        await ConnectAsync();\n\n        if (!_asbOptions.AutoProvision) \n            return;\n\n        topics = topics.Concat(_asbOptions!.SQLFilters?.Select(o => o.Key) ?? []);\n\n        var allRules = _administrationClient!.GetRulesAsync(_asbOptions!.TopicPath, _subscriptionName).ToBlockingEnumerable();\n        var allRuleNames = allRules.Select(o => o.Name);\n\n        foreach (var newRule in topics.Except(allRuleNames))\n        {\n            var isSqlRule = _asbOptions.SQLFilters?.FirstOrDefault(o => o.Key == newRule).Value is not null;\n\n            RuleFilter? currentRuleToAdd = default;\n\n            if (isSqlRule)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.AzureServiceBus/AzureServiceBusConsumerClient.cs#L38-L74","documentation":"SubscribeAsync on the Azure Service Bus consumer requires a non-null topics collection to create subscriptions/entities. Null is treated as a programming error and throws ArgumentNullException; an empty list is allowed (no-op after connect).","triggerScenarios":"Calling AzureServiceBusConsumerClient.SubscribeAsync(null) directly or via a custom bootstrap that forwards a null subscriber collection; can also happen in CAP's ConsistencyBootstrapper path when subscriber descriptors were never initialized.","commonSituations":"Custom CAP forks replacing the consumer client factory with one that passes null when there are no consumers; refactors where a topic list built from reflection/config came back null instead of empty.","solutions":["Pass a non-null collection; use Array.Empty<string>() for no topics","Register subscribers with x.AddSubscribe<T>() so CAP builds the topic list","Guard the call site against null before invoking SubscribeAsync","Catch ArgumentNullException during bootstrap and log which transport failed"],"exampleFix":"// before\nawait asbConsumer.SubscribeAsync(topicsFromConfig); // null\n// after\nawait asbConsumer.SubscribeAsync(topicsFromConfig ?? Enumerable.Empty<string>());","handlingStrategy":"validation","validationCode":"if (topics is null) throw new InvalidOperationException(\"topics must not be null\");","typeGuard":"bool IsValidTopics(IEnumerable<string>? t) => t is not null;","tryCatchPattern":"try { await client.SubscribeAsync(topics); } catch (ArgumentNullException ex) when (ex.ParamName == \"topics\") { logger.LogError(ex, \"ASB SubscribeAsync got null topics\"); throw; }","preventionTips":["Default topic collections to empty lists at the source","Register consumers via AddSubscribe so CAP manages the topic list"],"tags":["dotnet","azure-service-bus","null-argument","subscription"],"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"}