{"record":{"id":"1702a65a231ed5b2","repo":"microsoft/aspire","slug":"azurekubernetesloadbalancerresource-lb-name-is-missing-its","errorCode":null,"errorMessage":"AzureKubernetesLoadBalancerResource '{lb.Name}' is missing its subnet binding.","messagePattern":"AzureKubernetesLoadBalancerResource '(.+?)' is missing its subnet binding\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentExtensions.cs","lineNumber":748,"sourceCode":"                    new MemberExpression(\n                        new MemberExpression(\n                            new MemberExpression(\n                                new IdentifierExpression(aks.BicepIdentifier),\n                                \"properties\"),\n                            \"ingressProfile\"),\n                        \"applicationLoadBalancer\"),\n                    \"identity\"),\n                \"objectId\");\n\n            // Dedupe (vnet, subnet) pairs so multiple LBs sharing a subnet only emit a\n            // single existing-resource declaration and a single role assignment.\n            var subnetExistingByKey = new Dictionary<string, SubnetResource>(StringComparer.Ordinal);\n            var assignedSubnets = new HashSet<string>(StringComparer.Ordinal);\n\n            foreach (var lb in aksResource.LoadBalancers)\n            {\n                var subnet = lb.SubnetResource\n                    ?? throw new InvalidOperationException($\"AzureKubernetesLoadBalancerResource '{lb.Name}' is missing its subnet binding.\");\n                var vnet = subnet.Parent;\n\n                // Reuse the canonical existing-VNet handle so emitted Bicep references\n                // match the rest of the module and we don't double-declare the resource.\n                var existingVnet = (VirtualNetwork)vnet.AddAsExistingResource(infrastructure);\n\n                var subnetIdentifier = $\"{existingVnet.BicepIdentifier}_{Infrastructure.NormalizeBicepIdentifier(subnet.Name)}_existing\";\n                if (!subnetExistingByKey.TryGetValue(subnetIdentifier, out var existingSubnet))\n                {\n                    existingSubnet = SubnetResource.FromExisting(subnetIdentifier);\n                    existingSubnet.Parent = existingVnet;\n                    existingSubnet.Name = subnet.SubnetName;\n                    infrastructure.Add(existingSubnet);\n                    subnetExistingByKey[subnetIdentifier] = existingSubnet;\n                }\n\n                if (!assignedSubnets.Add(subnetIdentifier))\n                {","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentExtensions.cs#L730-L766","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nvar lb = aks.AddLoadBalancer(\"public-lb\");\n// after\nvar vnet = aks.AddVirtualNetwork(\"vnet\");\nvar subnet = vnet.AddSubnet(\"lb-subnet\", \"10.0.1.0/24\");\nvar lb = aks.AddLoadBalancer(\"public-lb\").WithSubnet(subnet);","handlingStrategy":"validation","validationCode":"foreach (var lb in aksResource.LoadBalancers)\n{\n    if (lb.SubnetResource is null)\n        throw new InvalidOperationException($\"Load balancer '{lb.Name}' must be bound to a subnet before publish/deploy.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["azure","aks","subnet","load-balancer","configuration"],"backgroundTag":"missing-required-argument","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"}