microsoft/aspire · error · InvalidOperationException
App Service plan id ' ' does not contain a subscription id.
Error message
App Service plan id '{appServicePlanId}' does not contain a subscription id. What it means
GetSubscriptionAndResourceGroup parses the App Service plan ID with Azure ResourceIdentifier; a subscription id is required to build the portal resource-group URL. Missing it throws this InvalidOperationException.
Solutions
- Ensure the plan ID is a full ARM ID: /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.Web/serverfarms/<plan>
- Return the plan resource's .id property from the Bicep output rather than a name
- Validate the ID with ResourceIdentifier before parsing
- Fix the emitting module/deployment output
Defensive patterns
Strategy: validation
Validate before calling
if (Azure.ResourceManager.ResourceIdentifier.TryParse(planId, out var rid) && rid.SubscriptionId is not null)
{
// safe to parse
} Type guard
bool HasSubscription(string? id) => id is not null && id.Contains("/subscriptions/"); Try / catch
try { var link = await AppSvcUrls.GetPortalLinkAsync(env, site, slot, ct); }
catch (InvalidOperationException ex) when (ex.Message.Contains("does not contain a subscription id")) { /* log malformed plan id */ } Prevention
- Return serverfarms .id from Bicep outputs, not names
- Validate ARM IDs with ResourceIdentifier before parsing
- Avoid placeholder plan IDs in test/stub environments
When it happens
Trigger: PlanIdOutputReference value is not a fully-qualified ARM resource ID (no /subscriptions/<id>/ segment) — e.g. a partial ID or placeholder from a custom module.
Common situations: Stubbed plan IDs in tests; custom Bicep outputs returning names instead of full IDs; upstream deployment misconfiguration.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Container app environment id
- Container app environment id
- Azure deployment for
- Azure deployment for
- Azure resources cannot be managed because the Azure…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/00b91a1c0f76ab04.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.AppService/AppSvcUrls.cs:34
internal static async Task<MarkdownString> GetPortalLinkAsync(AzureAppServiceEnvironmentResource computerEnv, string siteName, string? deploymentSlot, CancellationToken cancellationToken)
{
var planIdValue = await computerEnv.PlanIdOutputReference.GetValueAsync(cancellationToken).ConfigureAwait(false)
?? throw new InvalidOperationException($"Missing app service plan id output for '{computerEnv.Name}'.");
var (subscriptionId, resourceGroupName) = GetSubscriptionAndResourceGroup(planIdValue);
var resourceId = $"{AzurePortalUrls.GetResourceGroupResourceId(subscriptionId, resourceGroupName)}{SiteResourceType}{siteName}";
if (!string.IsNullOrWhiteSpace(deploymentSlot))
{
resourceId += $"{SlotPathPrefix}{deploymentSlot}";
}
return AzurePortalUrls.GetResourceLink(resourceId);
}
private static (string SubscriptionId, string ResourceGroupName) GetSubscriptionAndResourceGroup(string appServicePlanId)
{
var planId = new ResourceIdentifier(appServicePlanId);
var subscriptionId = planId.SubscriptionId ?? throw new InvalidOperationException($"App Service plan id '{appServicePlanId}' does not contain a subscription id.");
var resourceGroupName = planId.ResourceGroupName ?? throw new InvalidOperationException($"App Service plan id '{appServicePlanId}' does not contain a resource group name.");
return (subscriptionId, resourceGroupName);
}
}
View on GitHub (pinned to 25830f84bd)