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
- Await the LoginCompleted event (or poll ConnectedState == 1 with a timeout) before sending shortcuts.
- Register a handler for OnDisconnected to suppress shortcut-sending until reconnected.
- 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
- Only call SendShortcut after the LoginCompleted event fires.
- Register an OnDisconnected handler to set a 'shortcuts disabled' flag.
- Implement a connection-state gate in the automation layer.
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
- 动作 {snapshot.Description} 执行 {attempts} 次后,等待 {snapshot.Targ
- 同一个 BvFlow 不能并发执行
- BvFlow 第 {i + 1} 步执行失败:{step.Description}
- BvFlow 已经开始执行,不能再添加步骤
- 当前没有可用的桌面分身,请先启动桌面分身。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/e1dc4d779db14495.
Report an issue: GitHub.