git-ecosystem/git-credential-manager · error · InvalidOperationException

Host is not Azure DevOps.

Error message

Host is not Azure DevOps.

What it means

UriHelpers.CreateOrganizationUri throws this InvalidOperationException when the remote URI's host is not recognized as an Azure DevOps host (dev.azure.com or *.visualstudio.com). GetOrganizationName relies on this method to build the organization URI, and organization extraction is only defined for Azure DevOps URLs, so any other host is rejected.

Solutions

  1. Ensure the remote is a cloud Azure DevOps URL: https://dev.azure.com/org/Project/_git/repo or https://org.visualstudio.com/Project/_git/repo.
  2. If you truly target on-prem Azure DevOps Server, do not use the Azure DevOps organization helpers — use the generic host provider/basic auth configuration.
  3. Check credential.provider / GCM_PROVIDER is not forcing azuredevops for non-Azure remotes; unset it to allow auto-detection.
  4. Fix typos in the host (e.g. dev.azure.com misspellings) by re-setting the remote URL.

Example fix

// before
var org = UriHelpers.GetOrganizationName(new Uri("https://tfs.contoso.local/DefaultCollection/Project")); // throws
// after (cloud Azure DevOps URL)
var org = UriHelpers.GetOrganizationName(new Uri("https://dev.azure.com/contoso/Project"));
Defensive patterns

Strategy: validation

Validate before calling

var uri = new Uri(remoteUri);
bool isAzureDevOps = uri.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase)
    || uri.Host.EndsWith(".visualstudio.com", StringComparison.OrdinalIgnoreCase);
if (!isAzureDevOps)
    throw new InvalidOperationException($"{remoteUri} is not an Azure DevOps host; GetOrganizationName cannot be used.");

Type guard

static bool CanGetOrganizationName(Uri remoteUri) =>
    remoteUri?.IsAbsoluteUri == true
    && (remoteUri.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase)
        || remoteUri.Host.EndsWith(".visualstudio.com", StringComparison.OrdinalIgnoreCase));

Try / catch

try { return UriHelpers.GetOrganizationName(remoteUri); }
catch (InvalidOperationException ex) when (ex.Message == "Host is not Azure DevOps.")
{
    // non-Azure host: use generic host handling instead
    return null;
}

Prevention

When it happens

Trigger: Calling GetOrganizationName (which delegates to CreateOrganizationUri) with a remoteUri whose Host is not dev.azure.com and does not end in visualstudio.com — e.g. github.com, a self-hosted Azure DevOps Server FQDN, or a typo'd Azure host.

Common situations: Pointing the Azure DevOps authentication helper at GitHub or other remotes; using on-prem Azure DevOps Server (e.g. https://tfs.contoso.local) which is not a cloud Azure DevOps host; migrating remotes between hosts and forgetting to switch provider/helper config.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/081cb9dcd3fbad18. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.AzureRepos/UriHelpers.cs:132

        /// Thrown if <see cref="GitRequest.Protocol"/> is null or white space.
        /// <para/>
        /// Thrown if <see cref="GitRequest.Host"/> is null or white space.
        /// <para/>
        /// Thrown if <see cref="GitRequest.Host"/> is not an Azure DevOps hostname.
        /// <para/>
        /// Thrown if both of <see cref="GitRequest.UserName"/> or <see cref="GitRequest.Path"/>
        /// are null or white space when <see cref="GitRequest.Host"/> is an Azure-style URL
        /// ('dev.azure.com' rather than '*.visualstudio.com').
        /// </exception>
        public static Uri CreateOrganizationUri(Uri remoteUri, out string orgName)
        {
            EnsureArgument.AbsoluteUri(remoteUri, nameof(remoteUri));

            orgName = null;

            if (!IsAzureDevOpsHost(remoteUri.Host))
            {
                throw new InvalidOperationException("Host is not Azure DevOps.");
            }

            var ub = new UriBuilder
            {
                Scheme = remoteUri.Scheme,
                Host = remoteUri.Host,
            };

            if (!remoteUri.IsDefaultPort)
            {
                ub.Port = remoteUri.Port;
            }

            // Extract the organization name for Azure ('dev.azure.com') style URLs.
            // The older *.visualstudio.com URLs contained the organization name in the host already.
            if (IsDevAzureComHost(remoteUri.Host))
            {
                string firstPathComponent = GetFirstPathComponent(remoteUri.AbsolutePath);

View on GitHub (pinned to e8ce762cd0)