microsoft/aspire · error
AzureKubernetesLoadBalancerResource
Error message
AzureKubernetesLoadBalancerResource '{lb.Name}' is missing its subnet binding. What it means
While configuring the AKS infrastructure for an AzureKubernetesEnvironmentResource, each configured load balancer resource must carry a subnet binding (SubnetResource) so the emitted Bicep can wire its frontend into the right VNet subnet. This error is thrown when a AzureKubernetesLoadBalancerResource was added to the environment without a subnet.
Solutions
- Assign a SubnetResource to every load balancer added to the AKS environment, e.g. via the extension API that takes/binds a subnet from a VNet
- Check the AppHost Program.cs for every load balancer definition and ensure each is bound to an existing subnet
- Guard custom code that constructs AzureKubernetesLoadBalancerResource directly so it always sets SubnetResource before publish
- Improve developer experience by validating at configuration time (fail fast when the extension is called without a subnet)
Example fix
// before
var lb = aks.AddLoadBalancer("public-lb");
// after
var vnet = aks.AddVirtualNetwork("vnet");
var subnet = vnet.AddSubnet("lb-subnet", "10.0.1.0/24");
var lb = aks.AddLoadBalancer("public-lb").WithSubnet(subnet); Defensive patterns
Strategy: validation
Validate before calling
foreach (var lb in aksResource.LoadBalancers)
{
if (lb.SubnetResource is null)
throw new InvalidOperationException($"Load balancer '{lb.Name}' must be bound to a subnet before publish/deploy.");
} Prevention
- Always bind each load balancer to a subnet created from an AKS virtual network resource in the AppHost
- Add a publish-time validation step (or unit test) that iterates LoadBalancers and asserts SubnetResource is set
- Keep load balancer and subnet definitions adjacent in Program.cs so the dependency is visible
When it happens
Trigger: Calling the load-balancer configuration API (e.g. WithLoadBalancer-style extension on the AKS environment) and not assigning a subnet resource to the returned AzureKubernetesLoadBalancerResource before ConfigureAksInfrastructure runs during publish/deploy.
Common situations: Forgetting to chain the subnet assignment when adding a load balancer in the AppHost; a refactoring renamed the subnet property or removed the assignment; conditionally-created load balancers where the subnet is only set on some code path.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Could not resolve subnet ID for AGC load balancer
- Could not resolve the Azure subscription selected for…
- A BlobServiceClient could not be configured. Ensure valid…
- A BlobServiceClient could not be configured. Ensure valid…
- A ChatCompletionsClient could not be configured. Ensure…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/1702a65a231ed5b2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentExtensions.cs:748
new MemberExpression(
new MemberExpression(
new MemberExpression(
new IdentifierExpression(aks.BicepIdentifier),
"properties"),
"ingressProfile"),
"applicationLoadBalancer"),
"identity"),
"objectId");
// Dedupe (vnet, subnet) pairs so multiple LBs sharing a subnet only emit a
// single existing-resource declaration and a single role assignment.
var subnetExistingByKey = new Dictionary<string, SubnetResource>(StringComparer.Ordinal);
var assignedSubnets = new HashSet<string>(StringComparer.Ordinal);
foreach (var lb in aksResource.LoadBalancers)
{
var subnet = lb.SubnetResource
?? throw new InvalidOperationException($"AzureKubernetesLoadBalancerResource '{lb.Name}' is missing its subnet binding.");
var vnet = subnet.Parent;
// Reuse the canonical existing-VNet handle so emitted Bicep references
// match the rest of the module and we don't double-declare the resource.
var existingVnet = (VirtualNetwork)vnet.AddAsExistingResource(infrastructure);
var subnetIdentifier = $"{existingVnet.BicepIdentifier}_{Infrastructure.NormalizeBicepIdentifier(subnet.Name)}_existing";
if (!subnetExistingByKey.TryGetValue(subnetIdentifier, out var existingSubnet))
{
existingSubnet = SubnetResource.FromExisting(subnetIdentifier);
existingSubnet.Parent = existingVnet;
existingSubnet.Name = subnet.SubnetName;
infrastructure.Add(existingSubnet);
subnetExistingByKey[subnetIdentifier] = existingSubnet;
}
if (!assignedSubnets.Add(subnetIdentifier))
{View on GitHub (pinned to 25830f84bd)