babalae/better-genshin-impact · error · ArgumentOutOfRangeException

{paramName} 必须大于 0

Error message

{paramName} 必须大于 0

What it means

Thrown by SendShortcut when the RDP connection state is not 1 (Connected). The Connected property of the ActiveX control must read exactly 1 to indicate a fully established, interactive session. Any other value (0=not connected, 2/3=connecting/disconnecting) means keystrokes cannot be delivered to the remote desktop.

Source

Thrown at BetterGenshinImpact/Core/BgiVision/BvFlow.cs:310

    }

    internal BvLocator CreateAnyTextLocator(object texts, Rect rect)
    {
        return _page.GetByAnyText(texts, rect);
    }

    internal static IReadOnlyList<BvLocator> ParseTargets(object targets, string paramName)
    {
        return BvPage.ParseCollection<BvLocator>(targets, paramName)
            .Select(target => target.Clone())
            .ToArray();
    }

    internal static int ValidatePositive(int value, string paramName)
    {
        if (value <= 0)
        {
            throw new ArgumentOutOfRangeException(paramName, $"{paramName} 必须大于 0");
        }

        return value;
    }

    private BvFlowAction CreateImplicitPointAction(string description, Action<double, double> action)
    {
        return CreateAction(description, context =>
        {
            var (x, y) = context.GetLastMatchCenter();
            action(x, y);
            return Task.CompletedTask;
        });
    }

    private BvFlowAction CreatePointAction(string description, double x, double y, Action<double, double> action)
    {
        return CreateAction(description, _ =>

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Await the LoginCompleted event (or poll ConnectedState == 1 with a timeout) before sending shortcuts.
  2. Register a handler for OnDisconnected to suppress shortcut-sending until reconnected.
  3. Surface a user-facing message that the child session isn't ready rather than throwing into automation logic.

Example fix

// before
private void SendShortcut(KeyStroke[] strokes, string displayName)
{
    if (ConnectedState != 1)
        throw new InvalidOperationException($"桌面分身尚未完全连接,无法发送 {displayName}。");
    ...
}

// after — wait for connection or return false
private async Task<bool> SendShortcutAsync(KeyStroke[] strokes, string displayName, CancellationToken ct)
{
    using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct);
    linked.CancelAfter(TimeSpan.FromSeconds(10));
    while (ConnectedState != 1)
    {
        await Task.Delay(200, linked.Token);
    }
    SendShortcutCore(strokes, displayName);
    return true;
}
Defensive patterns

Strategy: validation

Validate before calling

// Check connection state before sending
if (ConnectedState != 1)
    throw new InvalidOperationException("桌面分身尚未完全连接");
// Or: await WaitForConnectionAsync(timeout)

Type guard

bool IsFullyConnected() => IsHandleCreated && ConnectedState == 1;

Try / catch

try { SendShortcut(strokes, "Win+Tab"); }
catch (InvalidOperationException ex) when (ex.Message.Contains("尚未完全连接"))
{
    // notify user / queue for retry after LoginCompleted
}

Prevention

When it happens

Trigger: SendShortcut is called for Win+Tab or other shortcuts while ConnectedState != 1. Happens when the caller invokes shortcut-sending before OnConnected/OnLoginComplete fires, after a disconnect, or during a reconnection attempt.

Common situations: Automation script tries to send a key combination immediately after calling Connect without waiting for the LoginCompleted event, or the RDP session dropped and the caller hasn't detected it yet.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/e1dc4d779db14495. Report an issue: GitHub.