{"record":{"id":"5a912e3bbfd3d0c0","repo":"microsoft/aspire","slug":"a-configureradiusinfrastructure-callback-renamed-container","errorCode":null,"errorMessage":"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.","messagePattern":"A ConfigureRadiusInfrastructure callback renamed container '(.+?)' to '(.+?)'\\. 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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Radius/Publishing/RadiusInfrastructureBuilder.cs","lineNumber":5202,"sourceCode":"    {\n        var name = (IBicepValue)container.ContainerName;\n\n        // An expression-backed BicepValue reports a default LiteralValue (null for string), but to\n        // stay consistent with the port guard we treat any non-null Expression as the non-literal\n        // signal.\n        if (name.Expression is not null || name.LiteralValue is not string literalName)\n        {\n            throw new InvalidOperationException(\n                $\"A ConfigureRadiusInfrastructure callback replaced container '{container.ContainerMapKey}' name \" +\n                $\"with a non-literal Bicep expression. The Aspire Radius publisher derives service discovery from \" +\n                $\"the original container name, so it must stay the literal resource name '{container.ContainerMapKey}' \" +\n                $\"(this is an Aspire limitation, not a Radius schema requirement). Remove the rename to keep the \" +\n                $\"emitted 'services__*' values addressing the deployed Service.\");\n        }\n\n        if (!string.Equals(literalName, container.ContainerMapKey, StringComparison.Ordinal))\n        {\n            throw new InvalidOperationException(\n                $\"A ConfigureRadiusInfrastructure callback renamed container '{container.ContainerMapKey}' to \" +\n                $\"'{literalName}'. The Aspire Radius publisher derives service discovery from the original container \" +\n                $\"name, so renaming it makes the emitted 'services__*' values point at a Service that is no longer \" +\n                $\"produced (this is an Aspire limitation, not a Radius schema requirement). Remove the rename to keep \" +\n                $\"cross-container calls working.\");\n        }\n    }\n\n    private static void ValidateServiceNameWithinKubernetesLimit(RadiusContainerConstruct container)\n    {\n        // The recipe names the Service `${normalizedName}-${containerName}` = `{top-level name}-\n        // {map key}`. For a baseline container the name-equality guard forces name == map key, so\n        // this is `{name}-{name}`; for a callback-added/portless container the name may legitimately\n        // differ, so compute the actual Service name from the literal top-level name when available.\n        var mapKey = container.ContainerMapKey;\n        var topLevelName = ((IBicepValue)container.ContainerName).LiteralValue is string literalName ? literalName : mapKey;\n        var serviceName = RadiusServiceDiscovery.GetServiceName(topLevelName, mapKey);\n        if (serviceName.Length > MaxKubernetesServiceNameLength)","sourceCodeStart":5184,"sourceCodeEnd":5220,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Radius/Publishing/RadiusInfrastructureBuilder.cs#L5184-L5220","documentation":"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.","triggerScenarios":"Inside a ConfigureRadiusInfrastructure callback, assigning container.ContainerName = \"newName\" (a literal string that differs from container.ContainerMapKey, compared Ordinal).","commonSituations":"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.","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"],"exampleFix":"// before\ncallback(ctx => { ctx.Container.ContainerName = \"api-svc\"; });\n// after\ncallback(ctx => { /* no rename: ContainerName stays the resource name */ });","handlingStrategy":"validation","validationCode":"if (!string.Equals((string?)((IBicepValue)container.ContainerName).LiteralValue, container.ContainerMapKey, StringComparison.Ordinal))\n    throw new InvalidOperationException(\"Do not rename containers in ConfigureRadiusInfrastructure.\");","typeGuard":"static bool NameUnchanged(IBicepValue name, string mapKey) => name.LiteralValue as string == mapKey;","tryCatchPattern":null,"preventionTips":["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"],"tags":["radius","bicep","publish-time","service-discovery"],"backgroundTag":"unsupported-operation","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"}