babalae/better-genshin-impact · error · InvalidDataException

命名管道 JSON 消息为空。

Error message

命名管道 JSON 消息为空。

What it means

Thrown by InstanceIpcProtocol.ReadJson when JsonConvert.DeserializeObject<InstanceIpcEnvelope> returns null — the UTF-8 payload decoded to the JSON literal `null` (or produced an envelope that Newtonsoft maps to null), which is not a valid IPC envelope.

Source

Thrown at BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs:144

        var payload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(envelope, SerializerSettings));
        await WriteFrameAsync(
            stream,
            InstanceIpcPayloadType.Utf8Json,
            payload,
            cancellationToken).ConfigureAwait(false);
    }

    internal static InstanceIpcEnvelope ReadJson(InstanceIpcFrame frame)
    {
        if (frame.PayloadType != InstanceIpcPayloadType.Utf8Json)
        {
            throw new InvalidDataException($"预期 JSON 帧,实际为 {frame.PayloadType}。");
        }

        return JsonConvert.DeserializeObject<InstanceIpcEnvelope>(
                   Encoding.UTF8.GetString(frame.Payload),
                   SerializerSettings)
               ?? throw new InvalidDataException("命名管道 JSON 消息为空。");
    }

    internal static async ValueTask WriteRelativeMouseBatchAsync(
        Stream stream,
        ulong firstSequence,
        IReadOnlyList<RelativeMouseSample> samples,
        CancellationToken cancellationToken)
    {
        if (samples.Count is <= 0 or > 64)
        {
            throw new ArgumentOutOfRangeException(nameof(samples), "相对鼠标批次必须包含 1 到 64 个样本。");
        }

        var payload = CreateRelativeMousePayload(firstSequence, samples);

        await WriteFrameAsync(
            stream,
            InstanceIpcPayloadType.RelativeMouseBatch,

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Restart both instances to re-establish the pipe.
  2. Ensure both instances run the same build (serialization contract must match).
  3. If reproducing, inspect the raw UTF-8 payload — a literal `null` token points to a peer-side bug in envelope construction.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var envelope = InstanceIpcProtocol.ReadJson(frame.Value);
}
catch (InvalidDataException ex) when (ex.Message.Contains("为空"))
{
    logger.LogError(ex, "Received null JSON envelope; peer bug or corruption");
}

Prevention

When it happens

Trigger: The peer sent the JSON token `null` as the frame payload, or the serializer settings (NullValueHandling.Ignore combined with an all-null envelope) collapsed the result to null.

Common situations: A peer bug that serializes a null/default envelope; protocol corruption that yields a `null` token; a deserialization contract change that no longer maps the JSON to the envelope type.

Related errors


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