{"record":{"id":"74424658f4d0b247","repo":"dotnetcore/CAP","slug":"origin-character-string-length-must-between-1-256","errorCode":null,"errorMessage":"origin character string length must between 1~256!","messagePattern":"origin character string length must between 1~256!","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.AmazonSQS/TopicNormalizer.cs","lineNumber":13,"sourceCode":"﻿// Copyright (c) .NET Core Community. All rights reserved.\n// Licensed under the MIT License. See License.txt in the project root for license information.\n\nusing System;\n\nnamespace DotNetCore.CAP.AmazonSQS;\n\ninternal static class TopicNormalizer\n{\n    public static string NormalizeForAws(this string origin)\n    {\n        if (origin.Length > 256)\n            throw new ArgumentOutOfRangeException(nameof(origin) + \" character string length must between 1~256!\");\n        return origin.Replace(\".\", \"-\").Replace(\":\", \"_\");\n    }\n}","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.AmazonSQS/TopicNormalizer.cs#L1-L16","documentation":"SNS topic names are limited to 256 characters, so NormalizeForAws validates the length before sanitizing '.' and ':' characters. Passing a string longer than 256 characters throws ArgumentOutOfRangeException naming the origin parameter.","triggerScenarios":"Publishing or subscribing to a CAP topic whose name (after transport prefixing) exceeds 256 characters, then hitting the SQS/SNS transport which normalizes the name via NormalizeForAws.","commonSituations":"Very long, namespaced topic names (e.g. company.environment.service.event.version concatenated) that exceed the AWS limit; also long cloud environment prefixes producing names valid in RabbitMQ/Kafka but invalid in AWS.","solutions":["Shorten the CAP topic name so it is at most 256 characters","Use the TopicName prefix/shortening strategies: move versioning into message headers instead of the topic name","Choose a different transport (e.g. RabbitMQ/Kafka) if long names are a hard requirement, or alias short names","Add a startup validation rule that asserts all configured topic names are <= 256 chars before subscribing"],"exampleFix":"// before\nservices.AddCap(x => { x.ProducerTopics = new[] { \"mycompany.production.paymentservice.invoice.generated.v1.final\" + longSuffix }; });\n// after\nservices.AddCap(x => { x.ProducerTopics = new[] { \"invoice-generated-v1\" }; }); // <= 256 chars, no '.'/':'\n","handlingStrategy":"validation","validationCode":"if (origin is null || origin.Length is < 1 or > 256) throw new ArgumentOutOfRangeException(nameof(origin), \"AWS topic name must be 1-256 characters\");","typeGuard":"bool IsValidAwsTopicName(string? s) => !string.IsNullOrEmpty(s) && s.Length <= 256;","tryCatchPattern":"try { var name = origin.NormalizeForAws(); } catch (ArgumentOutOfRangeException ex) { logger.LogError(ex, \"Topic name exceeds AWS 256-char limit\"); throw; }","preventionTips":["Keep CAP topic names short and AWS-safe (avoid '.', ':')","Validate all configured topic names at startup against the 256-char limit","Move versioning/details into headers instead of the topic name"],"tags":["dotnet","aws","sns","argument-out-of-range","naming"],"backgroundTag":"argument-out-of-range","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"}