{"record":{"id":"74987f97a8974e05","repo":"microsoft/aspire","slug":"container-app-environment-id-containerappenvironmentid-does-74987f","errorCode":null,"errorMessage":"Container app environment id '{containerAppEnvironmentId}' does not contain a resource group name.","messagePattern":"Container app environment id '(.+?)' does not contain a resource group name\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/ContainerAppUrls.cs","lineNumber":29,"sourceCode":"internal static class ContainerAppUrls\n{\n    private const string ContainerAppResourceType = \"/providers/Microsoft.App/containerApps/\";\n\n    internal static async Task<MarkdownString> GetPortalLinkAsync(AzureContainerAppEnvironmentResource containerAppEnv, string containerAppName, CancellationToken cancellationToken)\n    {\n        var environmentIdValue = await containerAppEnv.ContainerAppEnvironmentId.GetValueAsync(cancellationToken).ConfigureAwait(false)\n            ?? throw new InvalidOperationException($\"Missing container app environment id output for '{containerAppEnv.Name}'.\");\n        var (subscriptionId, resourceGroupName) = GetSubscriptionAndResourceGroup(environmentIdValue);\n        var resourceId = $\"{AzurePortalUrls.GetResourceGroupResourceId(subscriptionId, resourceGroupName)}{ContainerAppResourceType}{containerAppName}\";\n\n        return AzurePortalUrls.GetResourceLink(resourceId);\n    }\n\n    private static (string SubscriptionId, string ResourceGroupName) GetSubscriptionAndResourceGroup(string containerAppEnvironmentId)\n    {\n        var environmentId = new ResourceIdentifier(containerAppEnvironmentId);\n        var subscriptionId = environmentId.SubscriptionId ?? throw new InvalidOperationException($\"Container app environment id '{containerAppEnvironmentId}' does not contain a subscription id.\");\n        var resourceGroupName = environmentId.ResourceGroupName ?? throw new InvalidOperationException($\"Container app environment id '{containerAppEnvironmentId}' does not contain a resource group name.\");\n\n        return (subscriptionId, resourceGroupName);\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/ContainerAppUrls.cs#L11-L34","documentation":"Same parsing path as the subscription check: the environment ID must contain a resource group for the portal link URL. When ResourceIdentifier.ResourceGroupName is null, this InvalidOperationException is thrown.","triggerScenarios":"ContainerAppEnvironmentId is a valid subscription-scoped string but lacks a /resourceGroups/<rg>/ segment (e.g. subscription-level or malformed ID).","commonSituations":"Hand-constructed IDs in tests; outputs from custom modules returning partial IDs; typos like 'resourceGroup' (singular) in generated IDs.","solutions":["Ensure the ID includes /resourceGroups/<rg>/ segment","Regenerate the ID from the managed environment resource's .id rather than hand-building it","Validate with new ResourceIdentifier(id) and check ResourceGroupName before use","Fix the emitting Bicep module output to return the full resource id"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (Azure.ResourceManager.ResourceIdentifier.TryParse(environmentId, out var rid) && rid.ResourceGroupName is not null)\n{\n    // safe to parse\n}","typeGuard":"bool HasResourceGroup(string? id) => id is not null && id.Contains(\"/resourceGroups/\");","tryCatchPattern":"try { var link = await ContainerAppUrls.GetPortalLinkAsync(env, name, ct); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not contain a resource group name\")) { /* log malformed environment id */ }","preventionTips":["Ensure Bicep outputs include the resourceGroup segment of the ID","Construct IDs from resource .id properties, not string concatenation of parts","Spot-check generated IDs in azd outputs during development"],"tags":["azure","arm","resource-id","portal-link"],"backgroundTag":"invalid-identifier-format","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"}