microsoft/aspire · error · ArgumentException

Invalid region specified

Error message

Invalid region specified

What it means

DevTunnelOptions.Region only accepts members of the DevTunnelRegion enum (mapped internally to devtunnel's region codes). Any other value, including an out-of-range enum cast, throws ArgumentException('Invalid region specified').

Solutions

  1. Use a defined DevTunnelRegion member (e.g. DevTunnelRegion.USWest, AustraliaEast, JapanEast, BrazilSouth, SoutheastAsia)
  2. Enum.TryParse the config string into DevTunnelRegion and reject unknown values before assignment
  3. Leave Region null to use the service's default region
  4. Check the DevTunnelRegion enum in your package version for the exact member list

Example fix

// before
options.Region = (DevTunnelRegion)"eastus"; // invalid cast value -> throws
// after
if (!Enum.TryParse<DevTunnelRegion>(configRegion, out var region))
{
    throw new InvalidOperationException($"Unsupported region '{configRegion}'");
}
options.Region = region;
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Enum.IsDefined(typeof(DevTunnelRegion), regionValue))
    throw new InvalidOperationException($"Region {regionValue} is not supported");
options.Region = regionValue;

Type guard

static bool IsDefinedRegion(DevTunnelRegion r) => Enum.IsDefined(typeof(DevTunnelRegion), r);

Try / catch

try { options.Region = region; }
catch (ArgumentException ex) { logger.LogError(ex, "Unsupported dev tunnel region"); options.Region = null; }

Prevention

When it happens

Trigger: Assigning options.Region = (DevTunnelRegion)123 or any value not defined in DevTunnelRegion when configuring the dev tunnel resource.

Common situations: Reading a region string from configuration and casting it blindly to the enum; using Azure region names that devtunnel does not expose; enum drift after package upgrades.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4692ff994c91c527. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.DevTunnels/DevTunnelOptions.cs:79

    internal string RegionCode =>
        Region switch
        {
            DevTunnelRegion.WestEurope => "euw",
            DevTunnelRegion.UKSouth => "uks1",
            DevTunnelRegion.NorthEurope => "eun1",
            DevTunnelRegion.EastUs => "use",
            DevTunnelRegion.EastUs2 => "use2",
            DevTunnelRegion.WestUs2 => "usw2",
            DevTunnelRegion.WestUs3 => "usw3",
            DevTunnelRegion.CentralIndia => "inc1",
            DevTunnelRegion.SoutheastAsia => "asse",
            DevTunnelRegion.BrazilSouth => "brs",
            DevTunnelRegion.AustraliaCentral => "auc1",
            DevTunnelRegion.AustraliaEast => "aue",
            DevTunnelRegion.JapanEast => "jpe1",
            null => string.Empty,
            _ => throw new ArgumentException("Invalid region specified", nameof(Region)),
        };

    internal string ToLoggerString() => $"{{ Description={Description}, AllowAnonymous={AllowAnonymous}, Labels=[{string.Join(", ", Labels ?? [])}], Region={Region}, ExpirationHours={ExpirationHours} }}";
}

/// <summary>
/// Options for a dev tunnel port.
/// </summary>
public sealed class DevTunnelPortOptions
{
    /// <summary>
    /// A description for this port within the dev tunnel.
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// Whether to allow anonymous access to this port. If <c>null</c>, defaults to the parent tunnel's setting. Defaults to <c>null</c>.
    /// </summary>

View on GitHub (pinned to 25830f84bd)