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

RemoteUri must be defined to generate Bitbucket DC OAuth2…

Error message

RemoteUri must be defined to generate Bitbucket DC OAuth2 endpoint Urls

What it means

BitbucketRestApi's BaseUri property derives the REST API root from _context.Settings?.RemoteUri. When RemoteUri is null it throws the same ArgumentException because OAuth2 endpoint/REST URLs cannot be generated without a server URL.

Solutions

  1. Populate the settings with a valid remote URI before using BitbucketRestApi.
  2. Invoke the flow through git so the helper receives host/path and Settings.RemoteUri is set.
  3. Guard callers: check Context.Settings?.RemoteUri != null before constructing/restApi calls.

Example fix

// before
var api = new BitbucketRestApi(context); // Settings.RemoteUri == null -> throws
// after
if (context.Settings?.RemoteUri == null) throw new InvalidOperationException("RemoteUri required");
var api = new BitbucketRestApi(context);
Defensive patterns

Strategy: validation

Validate before calling

if (context.Settings?.RemoteUri == null) throw new InvalidOperationException("RemoteUri required before using BitbucketRestApi");

Type guard

bool remoteReady = !string.IsNullOrWhiteSpace(context?.Settings?.RemoteUri?.ToString());

Try / catch

try { var root = restApi.BaseUri; } catch (ArgumentException ex) when (ex.Message.Contains("RemoteUri")) { /* populate settings or abort */ }

Prevention

When it happens

Trigger: Constructing or using BitbucketRestApi for a Bitbucket DC host when Context.Settings is null or Settings.RemoteUri is null — e.g. API calls made before remote URL settings were populated by the credential query.

Common situations: Programmatic use of GCM's Bitbucket API classes with a context lacking settings; credential operations triggered outside a normal git remote query; tests/tools creating the context without RemoteUri.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Atlassian.Bitbucket/DataCenter/BitbucketRestApi.cs:152

            return authenticationMethods;
        }

        public void Dispose()
        {
            _httpClient?.Dispose();
        }

        private HttpClient HttpClient => _httpClient ??= _context.HttpClientFactory.CreateClient();

        private Uri ApiUri
        {
            get
            {
                var remoteUri = _context.Settings?.RemoteUri;
                if (remoteUri == null)
                {
                    throw new ArgumentException("RemoteUri must be defined to generate Bitbucket DC OAuth2 endpoint Urls");
                }

                return new Uri(BitbucketHelper.GetBaseUri(remoteUri) + "/rest/");
            }
        }
    }
}

View on GitHub (pinned to e8ce762cd0)