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

Host is not Azure DevOps.

Error message

Host is not Azure DevOps.

What it means

GetServiceName throws this InvalidOperationException when the remote URI does not match any recognized Azure DevOps host pattern (dev.azure.com or *.visualstudio.com) and is not a full-path legacy visualstudio.com URL. It is an internal invariant: the provider should only be invoked for Azure DevOps remotes, so reaching this line means the host check upstream failed.

Solutions

  1. Verify the remote URL is genuinely an Azure DevOps URL and fix it: git remote set-url origin https://dev.azure.com/<org>/<project>/_git/<repo>
  2. Check credential.provider or GCM provider configuration so the correct host provider handles this remote (e.g. set provider to github/gitlab/generic for non-AzDO hosts)
  3. Clear stale config forcing the azure provider: git config --unset credential.https://<host>.credentialProvider
Defensive patterns

Strategy: validation

Validate before calling

// C#
static bool IsAzureDevOpsHost(Uri u) =>
    u.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase) ||
    u.Host.EndsWith(".visualstudio.com", StringComparison.OrdinalIgnoreCase);

Type guard

static bool IsAzureDevOpsRemote(Uri remoteUri) =>
    remoteUri.Host.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase) ||
    remoteUri.Host.EndsWith(".visualstudio.com", StringComparison.OrdinalIgnoreCase);

Try / catch

try {
    var service = provider.Service;
} catch (InvalidOperationException ex) when (ex.Message == "Host is not Azure DevOps.") {
    // route to the correct host provider (github/gitlab/generic)
}

Prevention

When it happens

Trigger: Calling the Service property on AzureReposHostProvider (GetServiceName) with a remoteUri whose host is not dev.azure.com, *.visualstudio.com, and does not qualify as a full-path legacy URL.

Common situations: Misconfigured host provider selection (Azure DevOps provider used for GitHub/GitLab/Bitbucket remotes); typo'd host in the remote URL; custom provider routing sending non-AzDO URLs to this provider.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.AzureRepos/AzureReposHostProvider.cs:469

        {
            // dev.azure.com
            if (UriHelpers.IsDevAzureComHost(remoteUri.Host))
            {
                // We can never store the new dev.azure.com-style URLs against the full path because
                // we have forced the useHttpPath option to true to in order to retrieve the AzDevOps
                // organization name from Git.
                return UriHelpers.CreateOrganizationUri(remoteUri, out _).AbsoluteUri.TrimEnd('/');
            }

            // *.visualstudio.com
            if (UriHelpers.IsVisualStudioComHost(remoteUri.Host))
            {
                // If we're given the full path for an older *.visualstudio.com-style URL then we should
                // respect that in the service name.
                return remoteUri.WithoutUserInfo().AbsoluteUri.TrimEnd('/');
            }

            throw new InvalidOperationException("Host is not Azure DevOps.");
        }

        private static string GetAccountNameForCredentialQuery(GitRequest request)
        {
            if (!request.TryGetHostAndPort(out string hostName, out _))
            {
                throw new InvalidOperationException("Failed to parse host name and/or port");
            }

            // dev.azure.com
            if (UriHelpers.IsDevAzureComHost(hostName))
            {
                // We ignore the given username for dev.azure.com-style URLs because AzDevOps recommends
                // adding the organization name as the user in the remote URL (resulting in URLs like
                // https://org@dev.azure.com/org/foo/_git/bar) and we don't know if the given username
                // is an actual username, or the org name.
                // Use `null` as the account name so we match all possible credentials (regardless of
                // the account).

View on GitHub (pinned to e8ce762cd0)