microsoft/aspire · error · ArgumentException
Could not generate a unique name for service
Error message
Could not generate a unique name for service '{candidateName}' What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
try
{
var (name, created) = dcpNameGenerator.GetServiceName(candidateName);
}
catch (ArgumentException ex)
{
// Name generation exhausted 100 suffix attempts; restart AppHost / report bug.
logger.LogError(ex, "DCP could not generate a unique service name for '{Candidate}'.", candidateName);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Resource ' ' not found.
- Unknown file system entry type
- Unknown resource type
- A JSON Patch operation must contain string 'op' and 'path'…
- A purge task with the name
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5a49cd726fc9a434.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Dcp/DcpNameGenerator.cs:135
{
return (name, false);
}
var candidateName = !hasMultipleEndpoints
? GetObjectNameForResource(resource, _options.Value)
: GetObjectNameForResource(resource, _options.Value, endpoint.Name);
int suffix = 1;
string uniqueName = candidateName;
while (!_allServiceNames.Add(uniqueName))
{
uniqueName = $"{candidateName}-{suffix}";
suffix++;
if (suffix == 100)
{
// Should never happen, but we do not want to ever get into a infinite loop situation either.
throw new ArgumentException($"Could not generate a unique name for service '{candidateName}'");
}
}
_networkServices[key] = uniqueName;
return (uniqueName, true);
}
}
public static string GetRandomNameSuffix()
{
// RandomNameSuffixLength of lowercase characters
var suffix = PasswordGenerator.Generate(RandomNameSuffixLength, true, false, false, false, RandomNameSuffixLength, 0, 0, 0);
return suffix;
}
public string GetProjectHashSuffix()
{
// Compute a short hash of the content root path to differentiate between multiple AppHost projects with similar resource names
var suffix = _configuration["AppHost:Sha256"]!.Substring(0, RandomNameSuffixLength).ToLowerInvariant();View on GitHub (pinned to 25830f84bd)