babalae/better-genshin-impact · warning · InvalidOperationException
当前动作已经设置完成条件,不能再次修改或添加
Error message
当前动作已经设置完成条件,不能再次修改或添加
What it means
Thrown by DecodeImage when both the WPF BitmapDecoder and the SixLabors.ImageSharp fallback fail to decode the byte array into a valid image. The WPF path catches NotSupportedException or FileFormatException and falls back to ImageSharp; if ImageSharp also throws, an InvalidDataException wraps the ImageSharp exception. This means the bytes are not a recognizable or supported image format.
Source
Thrown at BetterGenshinImpact/Core/BgiVision/BvFlowAction.cs:257
retryInterval = _retryInterval ?? _flow.DefaultRetryInterval;
}
var targetDescription = DescribeTargets(targets, condition);
return _flow.AddActionStep(new BvFlowActionSnapshot(
_description,
_action,
targets,
targetDescription,
timeout,
retryInterval,
condition));
}
private void EnsureNotCompleted()
{
if (_completed)
{
throw new InvalidOperationException("当前动作已经设置完成条件,不能再次修改或添加");
}
}
private static void ValidateWaitOptions(int? timeout, int? retryInterval)
{
if (timeout is { } timeoutValue)
{
BvFlow.ValidatePositive(timeoutValue, nameof(timeout));
}
if (retryInterval is { } retryIntervalValue)
{
BvFlow.ValidatePositive(retryIntervalValue, nameof(retryInterval));
}
}
internal static string DescribeTargets(IReadOnlyList<BvLocator> targets, BvFlowCondition condition)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Inspect the InnerException (the ImageSharp exception) for the specific format error.
- Verify the source URL/path points to a real image (open it in a browser/image viewer).
- Check the first few bytes for a valid image magic number (PNG: 89 50 4E 47, JPEG: FF D8 FF).
- Convert the image to PNG or JPEG before referencing it in Markdown.
Example fix
// before
catch (Exception imageSharpException)
{
throw new InvalidDataException("无法解码 Markdown 图片。", imageSharpException);
}
// after — include format hint and degrade
catch (Exception imageSharpException)
{
_owner.ReportDiagnostic(new MarkdownDiagnostic(MarkdownDiagnosticSeverity.Warning,
$"无法解码图片(格式不支持或数据损坏):{imageSharpException.Message}"));
return MarkdownImageResult.Placeholder;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate image magic number before decoding if (bytes.Length < 4) return Placeholder; var isPng = bytes[0] == 0x89 && bytes[1] == 0x50; var isJpeg = bytes[0] == 0xFF && bytes[1] == 0xD8; var isGif = bytes[0] == 0x47 && bytes[1] == 0x49; if (!(isPng || isJpeg || isGif)) return Placeholder;
Type guard
static bool HasValidImageHeader(byte[] bytes) =>
bytes.Length >= 4 && (
(bytes[0] == 0x89 && bytes[1] == 0x50) || // PNG
(bytes[0] == 0xFF && bytes[1] == 0xD8) || // JPEG
(bytes[0] == 0x47 && bytes[1] == 0x49)); // GIF Try / catch
try { return DecodeImage(bytes); }
catch (InvalidDataException ex) { _logger.LogWarning(ex.Inner, "解码失败"); return Placeholder; } Prevention
- Check the image magic number before attempting full decode.
- Inspect the InnerException (ImageSharp) for specific format errors.
- Ensure downloaded bytes are complete (verify Content-Length vs actual).
When it happens
Trigger: DecodeImage receives bytes that are corrupted, truncated, or in an unsupported format. BitmapDecoder.Create throws NotSupportedException/FileFormatException (WPF can't handle it), then Image.Load<Bgra32> also throws (ImageSharp can't handle it).
Common situations: Downloaded image was truncated by a network error or proxy, the file is not actually an image (e.g. an HTML 404 page saved as .png), the format is exotic (e.g. HEIC, AVIF) unsupported by both decoders, or the bytes are zero-length.
Related errors
- 等待 {targetDescription} 超时({timeout}ms)
- 添加流程步骤后不能修改流程默认配置
- 没有可用的上一步识别位置,无法执行隐式坐标操作
- milliseconds 不能小于 0
- 一次性动作不支持 WithTimeout 或 WithRetryInterval,请使用 Until 系列方法设置重试条
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/eb5997630159aaca.
Report an issue: GitHub.