dotnetcore/CAP · error · ArgumentNullException
Value cannot be null. (Parameter 'topicNames')
Error message
Value cannot be null. (Parameter 'topicNames')
What it means
ArgumentNullException on 'topicNames' raised inside FetchTopicsAsync's topic-creation path (the guard shown in the constructor context is the pattern reused for topic collections): the sequence of topic names passed to the Kafka admin/client call was null, so metadata for topics could not be fetched. The faulting input is the topics collection supplied to the subscribe/fetch flow.
Solutions
- Ensure the topic list passed to SubscribeAsync/FetchTopicsAsync is non-null (default to an empty list)
- Register topics via CAP attributes/configuration so the list is always populated before subscription
- Null-coalesce at the call site: topics ?? Array.Empty<string>()
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs:48 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14).
Data as JSON: /api/errors/7b56269b123db7ab.
Report an issue: GitHub.
Appendix: source
Thrown at src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs:48
public KafkaConsumerClient(string groupId, byte groupConcurrent,
IOptions<KafkaOptions> options, IServiceProvider serviceProvider)
{
_groupId = groupId;
_groupConcurrent = groupConcurrent;
_semaphore = new SemaphoreSlim(groupConcurrent);
_serviceProvider = serviceProvider;
_kafkaOptions = options.Value ?? throw new ArgumentNullException(nameof(options));
}
public Func<TransportMessage, object?, Task>? OnMessageCallback { get; set; }
public Action<LogMessageEventArgs>? OnLogCallback { get; set; }
public BrokerAddress BrokerAddress => new("kafka", _kafkaOptions.Servers);
public async Task<ICollection<string>> FetchTopicsAsync(IEnumerable<string> topicNames)
{
if (topicNames == null) throw new ArgumentNullException(nameof(topicNames));
var regexTopicNames = topicNames.Select(Helper.WildcardToRegex).ToList();
var allowAutoCreate = true;
if (_kafkaOptions.MainConfig.TryGetValue("allow.auto.create.topics", out var autoCreateValue)
&& bool.TryParse(autoCreateValue, out var parsedValue))
{
allowAutoCreate = parsedValue;
}
if (allowAutoCreate)
{
try
{
var config = new AdminClientConfig(_kafkaOptions.MainConfig)
{ BootstrapServers = _kafkaOptions.Servers };
using var adminClient = new AdminClientBuilder(config).Build();View on GitHub (pinned to e52b8508e5)