{"record":{"id":"679c0cfd04c5a867","repo":"git-ecosystem/git-credential-manager","slug":"host-name-and-or-port-is-invalid","errorCode":null,"errorMessage":"Host name and/or port is invalid.","messagePattern":"Host name and/or port is invalid\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AzureRepos/UriHelpers.cs","lineNumber":46,"sourceCode":"                    return basePath + '/' + path;\n                }\n            }\n\n            return basePath + path;\n        }\n\n        /// <summary>\n        /// Check if the hostname is the legacy Azure DevOps hostname (*.visualstudio.com).\n        /// </summary>\n        /// <param name=\"request\">Git query arguments.</param>\n        /// <returns>True if the hostname is the legacy Azure DevOps host, false otherwise.</returns>\n        public static bool IsVisualStudioComHost(GitRequest request)\n        {\n            EnsureArgument.NotNull(request, nameof(request));\n\n            if (!request.TryGetHostAndPort(out string hostName, out _))\n            {\n                throw new InvalidOperationException(\"Host name and/or port is invalid.\");\n            }\n\n            return IsVisualStudioComHost(hostName);\n        }\n\n        /// <summary>\n        /// Check if the hostname is the legacy Azure DevOps hostname (*.visualstudio.com).\n        /// </summary>\n        /// <param name=\"host\">Hostname to check.</param>\n        /// <returns>True if the hostname is the legacy Azure DevOps host, false otherwise.</returns>\n        public static bool IsVisualStudioComHost(string host)\n        {\n            return host != null &&\n                   host.EndsWith(AzureDevOpsConstants.VstsHostSuffix, StringComparison.OrdinalIgnoreCase);\n        }\n\n        /// <summary>\n        /// Check if the hostname is the new Azure DevOps hostname (dev.azure.com).","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Microsoft.AzureRepos/UriHelpers.cs#L28-L64","documentation":"UriHelpers.IsVisualStudioComHost(GitRequest) throws this InvalidOperationException when request.TryGetHostAndPort fails, i.e. the request does not carry a parsable host (and required port) so the library cannot decide whether the remote is a legacy visualstudio.com host. It is a guard ensuring host classification never runs against missing host data.","triggerScenarios":"Calling IsVisualStudioComHost(request) (directly or via IsAzureDevOpsHost(request)/CreateOrganizationUri) with a GitRequest whose remote URL cannot yield a host name — empty or relative URL, malformed URI, or an address where the required port is absent per TryGetHostAndPort semantics.","commonSituations":"A remote URL configured without a scheme/host (e.g. git remote set-url origin /path/to/repo or ssh-style scp syntax) that GCM later tries to classify; programmatically constructing a GitRequest with an empty RequestUri; tests/tools passing a partially populated request.","solutions":["Inspect the remote URL: git remote -v; set a fully qualified absolute URL such as https://org.visualstudio.com/Project/_git/repo.","Ensure the URL includes a scheme (https://) and a host name; relative, file, or scp-like remotes cannot be classified.","If calling the API directly, construct the GitRequest with a valid absolute URI and a host/port that TryGetHostAndPort can extract.","Check the request's environment/arguments: a missing or malformed remote URL passed via env vars (e.g. GCM behaviors driven by remote URL) will fail host extraction."],"exampleFix":"// before\nvar request = new GitRequest(); // no remote URL -> no host\nbool isVsCom = UriHelpers.IsVisualStudioComHost(request);\n// after\nvar request = new GitRequest();\nrequest.RemoteUrl = new Uri(\"https://org.visualstudio.com/Project/_git/repo\");\nbool isVsCom = UriHelpers.IsVisualStudioComHost(request);","handlingStrategy":"validation","validationCode":"if (!Uri.TryCreate(remoteUrl, UriKind.Absolute, out var uri) || string.IsNullOrEmpty(uri.Host))\n    throw new ArgumentException($\"Remote URL '{remoteUrl}' must be absolute with a valid host before host classification.\");\nbool isVsCom = uri.Host.EndsWith(\".visualstudio.com\", StringComparison.OrdinalIgnoreCase);","typeGuard":"static bool HasParsableHost(GitRequest request) =>\n    request?.RemoteUrl is Uri u && Uri.CheckHostName(u.Host) != UriHostNameType.Unknown;","tryCatchPattern":"try { return UriHelpers.IsVisualStudioComHost(request); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Host name and/or port is invalid\"))\n{\n    // request lacks a usable host — treat as 'not visualstudio.com' and fix the URL upstream\n    return false;\n}","preventionTips":["Always configure remotes as absolute https URLs with scheme and host.","Call the string-host overload IsVisualStudioComHost(host) only after verifying TryGetHostAndPort/Uri parsing succeeded.","Reject relative, file, or scp-like remote URLs early in your tooling before invoking GCM host helpers.","Log the request's remote URL when this error occurs to spot blank/malformed remote config quickly."],"tags":["azure-devops","git-credentials","url-parsing","host-validation"],"backgroundTag":"invalid-url-format","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"}