microsoft/aspire · error · InvalidOperationException
A ConfigureRadiusInfrastructure callback renamed container
Error message
A ConfigureRadiusInfrastructure callback renamed container '{container.ContainerMapKey}' to '{literalName}'. The Aspire Radius publisher derives service discovery from the original container name, so renaming it makes the emitted 'services__*' values point at a Service that is no longer produced (this is an Aspire limitation, not a Radius schema requirement). Remove the rename to keep cross-container calls working. What it means
This error is thrown when a ConfigureRadiusInfrastructure callback renames a container to a different literal string. The Aspire Radius publisher generates the recipe's Kubernetes Service and 'services__*' discovery values from the original container name (ContainerMapKey); renaming makes the discovery values point at a Service that is never produced, breaking cross-container calls. Aspire fails at publish time instead of emitting a broken manifest.
Solutions
- Remove the rename so container.ContainerName stays equal to container.ContainerMapKey
- Rename the Aspire resource at model-build time (resource name) if a different deployed name is required
- Restore the original literal name in the callback
Example fix
// before
callback(ctx => { ctx.Container.ContainerName = "api-svc"; });
// after
callback(ctx => { /* no rename: ContainerName stays the resource name */ }); Defensive patterns
Strategy: validation
Validate before calling
if (!string.Equals((string?)((IBicepValue)container.ContainerName).LiteralValue, container.ContainerMapKey, StringComparison.Ordinal))
throw new InvalidOperationException("Do not rename containers in ConfigureRadiusInfrastructure."); Type guard
static bool NameUnchanged(IBicepValue name, string mapKey) => name.LiteralValue as string == mapKey;
Prevention
- Treat ContainerName as read-only inside Radius infrastructure callbacks
- Rename at the Aspire resource level if a different name is needed
- Add a unit test comparing callback output names to ContainerMapKey
When it happens
Trigger: Inside a ConfigureRadiusInfrastructure callback, assigning container.ContainerName = "newName" (a literal string that differs from container.ContainerMapKey, compared Ordinal).
Common situations: Developers rename containers to match external naming conventions or de-duplicate names across environments in the Radius customization callback, unaware Aspire ties service discovery to the original name.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- A ConfigureRadiusInfrastructure callback replaced container
- A ConfigureRadiusInfrastructure callback replaced port
- A ConfigureRadiusInfrastructure callback replaced the…
- A ConfigureRadiusInfrastructure callback changed port
- A ConfigureRadiusInfrastructure callback removed or…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5a912e3bbfd3d0c0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Radius/Publishing/RadiusInfrastructureBuilder.cs:5202
{
var name = (IBicepValue)container.ContainerName;
// An expression-backed BicepValue reports a default LiteralValue (null for string), but to
// stay consistent with the port guard we treat any non-null Expression as the non-literal
// signal.
if (name.Expression is not null || name.LiteralValue is not string literalName)
{
throw new InvalidOperationException(
$"A ConfigureRadiusInfrastructure callback replaced container '{container.ContainerMapKey}' name " +
$"with a non-literal Bicep expression. The Aspire Radius publisher derives service discovery from " +
$"the original container name, so it must stay the literal resource name '{container.ContainerMapKey}' " +
$"(this is an Aspire limitation, not a Radius schema requirement). Remove the rename to keep the " +
$"emitted 'services__*' values addressing the deployed Service.");
}
if (!string.Equals(literalName, container.ContainerMapKey, StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"A ConfigureRadiusInfrastructure callback renamed container '{container.ContainerMapKey}' to " +
$"'{literalName}'. The Aspire Radius publisher derives service discovery from the original container " +
$"name, so renaming it makes the emitted 'services__*' values point at a Service that is no longer " +
$"produced (this is an Aspire limitation, not a Radius schema requirement). Remove the rename to keep " +
$"cross-container calls working.");
}
}
private static void ValidateServiceNameWithinKubernetesLimit(RadiusContainerConstruct container)
{
// The recipe names the Service `${normalizedName}-${containerName}` = `{top-level name}-
// {map key}`. For a baseline container the name-equality guard forces name == map key, so
// this is `{name}-{name}`; for a callback-added/portless container the name may legitimately
// differ, so compute the actual Service name from the literal top-level name when available.
var mapKey = container.ContainerMapKey;
var topLevelName = ((IBicepValue)container.ContainerName).LiteralValue is string literalName ? literalName : mapKey;
var serviceName = RadiusServiceDiscovery.GetServiceName(topLevelName, mapKey);
if (serviceName.Length > MaxKubernetesServiceNameLength)View on GitHub (pinned to 25830f84bd)