{"record":{"id":"081cb9dcd3fbad18","repo":"git-ecosystem/git-credential-manager","slug":"host-is-not-azure-devops-081cb9","errorCode":null,"errorMessage":"Host is not Azure DevOps.","messagePattern":"Host is not Azure DevOps\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AzureRepos/UriHelpers.cs","lineNumber":132,"sourceCode":"        /// Thrown if <see cref=\"GitRequest.Protocol\"/> is null or white space.\n        /// <para/>\n        /// Thrown if <see cref=\"GitRequest.Host\"/> is null or white space.\n        /// <para/>\n        /// Thrown if <see cref=\"GitRequest.Host\"/> is not an Azure DevOps hostname.\n        /// <para/>\n        /// Thrown if both of <see cref=\"GitRequest.UserName\"/> or <see cref=\"GitRequest.Path\"/>\n        /// are null or white space when <see cref=\"GitRequest.Host\"/> is an Azure-style URL\n        /// ('dev.azure.com' rather than '*.visualstudio.com').\n        /// </exception>\n        public static Uri CreateOrganizationUri(Uri remoteUri, out string orgName)\n        {\n            EnsureArgument.AbsoluteUri(remoteUri, nameof(remoteUri));\n\n            orgName = null;\n\n            if (!IsAzureDevOpsHost(remoteUri.Host))\n            {\n                throw new InvalidOperationException(\"Host is not Azure DevOps.\");\n            }\n\n            var ub = new UriBuilder\n            {\n                Scheme = remoteUri.Scheme,\n                Host = remoteUri.Host,\n            };\n\n            if (!remoteUri.IsDefaultPort)\n            {\n                ub.Port = remoteUri.Port;\n            }\n\n            // Extract the organization name for Azure ('dev.azure.com') style URLs.\n            // The older *.visualstudio.com URLs contained the organization name in the host already.\n            if (IsDevAzureComHost(remoteUri.Host))\n            {\n                string firstPathComponent = GetFirstPathComponent(remoteUri.AbsolutePath);","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Microsoft.AzureRepos/UriHelpers.cs#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","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.","Check credential.provider / GCM_PROVIDER is not forcing azuredevops for non-Azure remotes; unset it to allow auto-detection.","Fix typos in the host (e.g. dev.azure.com misspellings) by re-setting the remote URL."],"exampleFix":"// before\nvar org = UriHelpers.GetOrganizationName(new Uri(\"https://tfs.contoso.local/DefaultCollection/Project\")); // throws\n// after (cloud Azure DevOps URL)\nvar org = UriHelpers.GetOrganizationName(new Uri(\"https://dev.azure.com/contoso/Project\"));","handlingStrategy":"validation","validationCode":"var uri = new Uri(remoteUri);\nbool isAzureDevOps = uri.Host.Equals(\"dev.azure.com\", StringComparison.OrdinalIgnoreCase)\n    || uri.Host.EndsWith(\".visualstudio.com\", StringComparison.OrdinalIgnoreCase);\nif (!isAzureDevOps)\n    throw new InvalidOperationException($\"{remoteUri} is not an Azure DevOps host; GetOrganizationName cannot be used.\");","typeGuard":"static bool CanGetOrganizationName(Uri remoteUri) =>\n    remoteUri?.IsAbsoluteUri == true\n    && (remoteUri.Host.Equals(\"dev.azure.com\", StringComparison.OrdinalIgnoreCase)\n        || remoteUri.Host.EndsWith(\".visualstudio.com\", StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { return UriHelpers.GetOrganizationName(remoteUri); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Host is not Azure DevOps.\")\n{\n    // non-Azure host: use generic host handling instead\n    return null;\n}","preventionTips":["Only call GetOrganizationName/CreateOrganizationUri for cloud Azure DevOps URLs.","Route on-prem Azure DevOps Server (non-cloud hosts) through the generic host provider, not AzureRepos helpers.","Guard with a host check (dev.azure.com or *.visualstudio.com) before invoking organization extraction.","Re-verify remotes after host migrations (e.g. GitHub imports) since the old URL may still be configured."],"tags":["azure-devops","git-credentials","host-validation","url-parsing"],"backgroundTag":"invalid-argument-value","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}