{"record":{"id":"37196f240df4c317","repo":"microsoft/aspire","slug":"only-ipv4-cidr-notation-is-supported-cidr","errorCode":null,"errorMessage":"Only IPv4 CIDR notation is supported: '{cidr}'.","messagePattern":"Only IPv4 CIDR notation is supported: '(.+?)'\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sql/SubnetAddressAllocator.cs","lineNumber":108,"sourceCode":"                return true;\n            }\n        }\n\n        return false;\n    }\n\n    internal static (uint Start, uint End) ParseCidr(string cidr)\n    {\n        var parts = cidr.Split('/');\n        if (parts.Length != 2 || !int.TryParse(parts[1], out var prefix) || prefix < 0 || prefix > 32)\n        {\n            throw new FormatException($\"Invalid CIDR notation: '{cidr}'.\");\n        }\n\n        var ip = IPAddress.Parse(parts[0]);\n        if (ip.AddressFamily != AddressFamily.InterNetwork)\n        {\n            throw new FormatException($\"Only IPv4 CIDR notation is supported: '{cidr}'.\");\n        }\n\n        var bytes = ip.GetAddressBytes();\n        var address = (uint)((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]);\n\n        // Compute the network mask\n        var mask = prefix == 0 ? 0u : uint.MaxValue << (32 - prefix);\n        var networkAddress = address & mask;\n        var broadcastAddress = networkAddress | ~mask;\n\n        return (networkAddress, broadcastAddress);\n    }\n\n    private static string UintToIp(uint address)\n    {\n        return $\"{(address >> 24) & 0xFF}.{(address >> 16) & 0xFF}.{(address >> 8) & 0xFF}.{address & 0xFF}\";\n    }\n}","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sql/SubnetAddressAllocator.cs#L90-L126","documentation":"ParseCidr only supports IPv4 addresses. After parsing the IP part of a CIDR string with IPAddress.Parse, it checks AddressFamily and throws FormatException if the address is not InterNetwork (IPv4). Subnet arithmetic in this allocator is implemented with 32-bit uint math, so IPv6 cannot be handled.","triggerScenarios":"Passing an IPv6 CIDR such as 'fd00::/8' or '::1/128' into AllocateDeploymentScriptSubnet or any code path that calls ParseCidr.","commonSituations":"Using a dual-stack or IPv6-only vnet address space, copying an IPv6 prefix from Azure portal, or defaulting to IPv6 in custom networking configuration.","solutions":["Use an IPv4 CIDR (e.g. '10.0.0.0/16') for the vnet address space","Remove IPv6 address-space entries and rely on an IPv4 range for the deployment-script subnet","Pre-validate address families with IPAddress.Parse and check AddressFamily.InterNetwork before calling"],"exampleFix":"// before\n.WithAddressSpace(\"fd00:db8::/48\") // IPv6-only vnet\n// after\n.WithAddressSpace(\"10.0.0.0/16\") // IPv4 CIDR required","handlingStrategy":"validation","validationCode":"bool IsIPv4Cidr(string cidr) =>\n    System.Net.IPAddress.TryParse(cidr.Split('/')[0], out var ip)\n    && ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork;","typeGuard":null,"tryCatchPattern":"try { ParseCidr(cidr); }\ncatch (FormatException ex) when (ex.Message.Contains(\"IPv4\")) { throw new NotSupportedException(\"IPv6 address spaces are not supported for subnet allocation\", ex); }","preventionTips":["Use IPv4 address spaces for vnets managed by Aspire","Filter out IPv6 entries from any address-space lists before allocation","Document the IPv4-only constraint in shared networking configuration"],"tags":["azure","networking","cidr","ipv6","ipv4"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}