{"record":{"id":"5a49cd726fc9a434","repo":"microsoft/aspire","slug":"could-not-generate-a-unique-name-for-service-candidatename","errorCode":null,"errorMessage":"Could not generate a unique name for service '{candidateName}'","messagePattern":"Could not generate a unique name for service '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpNameGenerator.cs","lineNumber":135,"sourceCode":"            {\n                return (name, false);\n            }\n\n            var candidateName = !hasMultipleEndpoints\n                ? GetObjectNameForResource(resource, _options.Value)\n                : GetObjectNameForResource(resource, _options.Value, endpoint.Name);\n\n            int suffix = 1;\n            string uniqueName = candidateName;\n\n            while (!_allServiceNames.Add(uniqueName))\n            {\n                uniqueName = $\"{candidateName}-{suffix}\";\n                suffix++;\n                if (suffix == 100)\n                {\n                    // Should never happen, but we do not want to ever get into a infinite loop situation either.\n                    throw new ArgumentException($\"Could not generate a unique name for service '{candidateName}'\");\n                }\n            }\n            _networkServices[key] = uniqueName;\n            return (uniqueName, true); \n        }\n    }\n\n    public static string GetRandomNameSuffix()\n    {\n        // RandomNameSuffixLength of lowercase characters\n        var suffix = PasswordGenerator.Generate(RandomNameSuffixLength, true, false, false, false, RandomNameSuffixLength, 0, 0, 0);\n        return suffix;\n    }\n\n    public string GetProjectHashSuffix()\n    {\n        // Compute a short hash of the content root path to differentiate between multiple AppHost projects with similar resource names\n        var suffix = _configuration[\"AppHost:Sha256\"]!.Substring(0, RandomNameSuffixLength).ToLowerInvariant();","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpNameGenerator.cs#L117-L153","documentation":"Aspire's DCP name generator assigns unique names to network services by appending incrementing numeric suffixes to a candidate name. If 100 attempts still collide, it gives up and throws this ArgumentException. This is a defensive guard against an infinite loop; the comment in the source says it should never happen in practice.","triggerScenarios":"Calling GetServiceName (via DCP publishing) when appending suffixes 1-99 to the candidate name all collide with already-registered names in the _networkServices dictionary. Requires the same candidateName to be reused dozens of times within one app model lifetime.","commonSituations":"Running many resources with identical names under a misbehaving model where names are repeatedly re-registered (e.g., dev loops with hot reload recreating the same resource name over and over); practically always indicates an internal bookkeeping bug rather than user error.","solutions":["Restart the AppHost to clear the in-memory _networkServices name cache","Check for duplicate or auto-generated resource names in the application model and make resource names unique","If reproducible, file a bug against Aspire.Hosting DCP name generation with reproduction steps"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var (name, created) = dcpNameGenerator.GetServiceName(candidateName);\n}\ncatch (ArgumentException ex)\n{\n    // Name generation exhausted 100 suffix attempts; restart AppHost / report bug.\n    logger.LogError(ex, \"DCP could not generate a unique service name for '{Candidate}'.\", candidateName);\n}","preventionTips":["Use unique resource names in the application model","Avoid repeatedly re-registering the same candidate name in a single AppHost session","Restart the AppHost if name-generation errors appear after many model mutations"],"tags":["dcp","naming","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}