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

Unexpected interaction mode.

Error message

Unexpected interaction mode.

What it means

Thrown as the default case of the interaction mode switch in GetTokenForUserInteractiveAsync. The InteractionMode value passed in did not match Auto, EmbeddedWebView, SystemWebView, or DeviceCode, meaning an out-of-range or unknown enum value reached the method. This is an argument validation guard against enum values the switch does not handle.

Solutions

  1. Pass only valid InteractionMode values: Auto, EmbeddedWebView, SystemWebView, or DeviceCode.
  2. If the mode comes from config, validate/parse it defensively and fall back to InteractionMode.Auto on unrecognized values.
  3. Check for version skew: a mode defined in a newer library version cannot be used with an older build; update the library.

Example fix

// before
var mode = (InteractionMode)int.Parse(configValue);
await GetTokenForUserAsync(scopes, mode);
// after
var mode = Enum.TryParse<InteractionMode>(configValue, out var m) && m is InteractionMode.Auto or InteractionMode.DeviceCode or InteractionMode.SystemWebView or InteractionMode.EmbeddedWebView ? m : InteractionMode.Auto;
await GetTokenForUserAsync(scopes, mode);
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(InteractionMode), mode)) mode = InteractionMode.Auto;

Type guard

static bool IsValidInteractionMode(InteractionMode mode) =>
    mode is InteractionMode.Auto or InteractionMode.EmbeddedWebView
        or InteractionMode.SystemWebView or InteractionMode.DeviceCode;

Try / catch

try
{
    token = await auth.GetTokenForUserAsync(scopes, mode);
}
catch (ArgumentOutOfRangeException ex)
{
    // invalid mode value from config; retry with Auto
    token = await auth.GetTokenForUserAsync(scopes, InteractionMode.Auto);
}

Prevention

When it happens

Trigger: Calling GetTokenForUserAsync (or GetTokenForUserInteractiveAsync) with an explicit interactionMode argument that is not a defined/handled InteractionMode value — typically from an unvalidated cast of an int/setting string to the enum.

Common situations: User sets an invalid value in configuration (e.g. GCM interaction setting parsed into an out-of-range enum value), a caller casts a raw integer to InteractionMode without validating, or a newer enum member is passed to an older build.

Related errors


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

Appendix: source

Thrown at src/Core/Authentication/Entra/EntraAuthentication.PublicClient.cs:323

                    .WithUseEmbeddedWebView(true)
                    .WithEmbeddedWebViewOptions(GetEmbeddedWebViewOptions())
                    .ExecuteAsync(ct);

            case InteractionMode.SystemWebView:
                Context.Trace.WriteLine("Performing interactive authentication via system webview...");
                Context.Console.WriteInfo("opening browser to complete authentication...");
                return await app.AcquireTokenInteractive(scopes)
                    .WithUseEmbeddedWebView(false)
                    .WithSystemWebViewOptions(GetSystemWebViewOptions())
                    .ExecuteAsync(ct);

            case InteractionMode.DeviceCode:
                Context.Trace.WriteLine("Performing interactive authentication via device code...");
                return await app.AcquireTokenWithDeviceCode(scopes, ShowDeviceCodeAsync)
                    .ExecuteAsync(ct);

            default:
                throw new ArgumentOutOfRangeException(nameof(interactionMode), interactionMode, "Unexpected interaction mode.");
        }
    }

    private async Task<bool> UseDefaultAccountAsync(string userName, CancellationToken ct)
    {
        ThrowIfUserInteractionDisabled();

        if (Context.SessionManager.IsDesktopSession && Context.Settings.IsGuiPromptsEnabled)
        {
            if (TryFindHelperCommand(out string command, out string args))
            {
                var sb = new StringBuilder(args);
                sb.Append("default-account");
                sb.AppendFormat(" --username {0}", QuoteCmdArg(userName));

                IDictionary<string, string> result = await InvokeHelperAsync(command, sb.ToString());

                if (result.TryGetValue("use_default_account", out string str) && !string.IsNullOrWhiteSpace(str))

View on GitHub (pinned to e8ce762cd0)