{"record":{"id":"f94df66e386b984a","repo":"microsoft/aspire","slug":"cannot-allocate-a-29-subnet-in-virtual-network-vnet-name","errorCode":null,"errorMessage":"Cannot allocate a /29 subnet in virtual network '{vnet.Name}' (address space: {vnetAddressPrefix}). No non-overlapping address space is available. Use 'WithAdminDeploymentScriptSubnet' to provide an explicit subnet.","messagePattern":"Cannot allocate a /29 subnet in virtual network '(.+?)' \\(address space: (.+?)\\)\\. No non-overlapping address space is available\\. Use 'WithAdminDeploymentScriptSubnet' to provide an explicit subnet\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sql/SubnetAddressAllocator.cs","lineNumber":78,"sourceCode":"\n        while (candidate >= vnetStart)\n        {\n            var candidateEnd = candidate + blockSize - 1;\n\n            if (candidateEnd <= vnetEnd && !OverlapsAny(candidate, candidateEnd, existingRanges))\n            {\n                return $\"{UintToIp(candidate)}/{prefixLength}\";\n            }\n\n            if (candidate < blockSize)\n            {\n                break; // Prevent underflow\n            }\n\n            candidate -= blockSize;\n        }\n\n        throw new InvalidOperationException(\n            $\"Cannot allocate a /29 subnet in virtual network '{vnet.Name}' (address space: {vnetAddressPrefix}). \" +\n            $\"No non-overlapping address space is available. \" +\n            $\"Use 'WithAdminDeploymentScriptSubnet' to provide an explicit subnet.\");\n    }\n\n    private static bool OverlapsAny(uint start, uint end, List<(uint Start, uint End)> ranges)\n    {\n        foreach (var (rStart, rEnd) in ranges)\n        {\n            if (start <= rEnd && rStart <= end)\n            {\n                return true;\n            }\n        }\n\n        return false;\n    }\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sql/SubnetAddressAllocator.cs#L60-L96","documentation":"This error is thrown by SubnetAddressAllocator.AllocateDeploymentScriptSubnet when it cannot find a free /29 block inside the virtual network's address space. A /29 (8 addresses) is the minimum subnet needed for the Azure admin deployment script container. The allocator scans candidates from the top of the range downward and skips any block overlapping existing subnets; if none fits, it fails with guidance to supply an explicit subnet.","triggerScenarios":"Calling AllocateDeploymentScriptSubnet for a vnet whose address space is too small (smaller than /29), fully consumed by existing subnets, or fragmented so no aligned /29 fits without overlapping.","commonSituations":"Very small address prefixes (e.g. /30, /29 already used), vnets densely subdivided into subnets, or an address space that leaves no aligned gap for the deployment-script subnet.","solutions":["Call WithAdminDeploymentScriptSubnet to provide an explicit subnet with enough room","Enlarge the vnet address space (e.g. /24 or /16) so a free /29 fits","Remove or shrink existing subnets to free aligned address space","Verify the vnet address prefix is valid IPv4 CIDR with a prefix <= 29"],"exampleFix":"// before\nvar sql = builder.AddAzureSqlServer(\"sql\").WithAdminDeploymentScriptAutoGenSubnet(); // throws when vnet is full\n// after\nvar sql = builder.AddAzureSqlServer(\"sql\")\n    .WithAdminDeploymentScriptSubnet(\"10.0.255.0/29\");","handlingStrategy":"validation","validationCode":"// vnetAddressPrefix example: \"10.0.0.0/16\"\nvar parts = vnetAddressPrefix.Split('/');\nvar prefix = int.Parse(parts[1]);\nif (prefix > 29) throw new InvalidOperationException(\"Address space too small for a /29 deployment-script subnet\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide an explicit subnet with WithAdminDeploymentScriptSubnet when the vnet is small or crowded","Use a generous address space (e.g. /16) for development vnets","Keep the deployment-script subnet range reserved so other subnets never take it"],"tags":["azure","networking","subnet","cidr","vnet"],"backgroundTag":"value-out-of-range","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"}