{"record":{"id":"8b77d7e9f43b8b47","repo":"dotnetcore/CAP","slug":"value-cannot-be-null-parameter-topicnames","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'topicNames')","messagePattern":"Value cannot be null\\. \\(Parameter 'topicNames'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.AmazonSQS/AmazonSQSConsumerClient.cs","lineNumber":50,"sourceCode":"    private IAmazonSQS? _sqsClient;\n\n    public AmazonSQSConsumerClient(string groupId, byte groupConcurrent, IOptions<AmazonSQSOptions> options)\n    {\n        _groupId = groupId;\n        _groupConcurrent = groupConcurrent;\n        _amazonSQSOptions = options.Value;\n        _semaphore = new SemaphoreSlim(groupConcurrent);\n    }\n\n    public Func<TransportMessage, object?, Task>? OnMessageCallback { get; set; }\n\n    public Action<LogMessageEventArgs>? OnLogCallback { get; set; }\n\n    public BrokerAddress BrokerAddress => new(\"aws_sqs\", _queueUrl);\n\n    public async Task<ICollection<string>> FetchTopicsAsync(IEnumerable<string> topicNames)\n    {\n        if (topicNames == null) throw new ArgumentNullException(nameof(topicNames));\n\n        await ConnectAsync(true, false).ConfigureAwait(false);\n\n        var topicArns = new List<string>();\n        foreach (var topic in topicNames)\n        {\n            var createTopicRequest = new CreateTopicRequest(topic.NormalizeForAws());\n\n            var createTopicResponse = await _snsClient!.CreateTopicAsync(createTopicRequest).ConfigureAwait(false);\n\n            topicArns.Add(createTopicResponse.TopicArn);\n        }\n\n        await GenerateSqsAccessPolicyAsync(topicArns).ConfigureAwait(false);\n\n        return topicArns;\n    }\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.AmazonSQS/AmazonSQSConsumerClient.cs#L32-L68","documentation":"FetchTopicsAsync validates its topicNames parameter and throws ArgumentNullException when a null collection is passed. The consumer client needs at least an empty enumerable to resolve SNS topic ARNs; a null reference is treated as a programming error rather than 'no topics'.","triggerScenarios":"Calling AmazonSQSConsumerClient.FetchTopicsAsync(null) directly, or a CAP bootstrap path that passes a null topic-name collection into the SQS consumer during startup topic discovery.","commonSituations":"Building a custom consumer bootstrap on top of CAP where topics are read from configuration that was never populated (e.g. a missing config section deserialized to null) and the null collection is forwarded straight into FetchTopicsAsync.","solutions":["Ensure the IEnumerable<string> passed to FetchTopicsAsync is non-null; pass Array.Empty<string>() when there are no topics","Check that the configuration source feeding the topic list is populated before startup","If topics are truly optional, guard with topics ?? Enumerable.Empty<string>() before calling","Wrap the call in ArgumentNullException handling and fail fast with a clear log message"],"exampleFix":"// before\nawait consumerClient.FetchTopicsAsync(config.Topics); // config.Topics is null\n// after\nvar topics = config.Topics ?? new List<string>();\nawait consumerClient.FetchTopicsAsync(topics);","handlingStrategy":"validation","validationCode":"if (topicNames is null) throw new InvalidOperationException(\"topicNames must be provided (use an empty list for none)\");","typeGuard":"bool HasTopics(IEnumerable<string>? t) => t is not null;","tryCatchPattern":"try { await client.FetchTopicsAsync(topics); } catch (ArgumentNullException ex) when (ex.ParamName == \"topicNames\") { logger.LogError(ex, \"topicNames was null\"); throw; }","preventionTips":["Initialize topic collections with Array.Empty<string>() instead of null","Fail fast at configuration load time if the topic list section is missing"],"tags":["dotnet","null-argument","sqs","configuration"],"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"}