JeffreySu/WeiXinMPSDK · error · InvalidDataException

Finance SDK 返回的会话内容为空。

Error message

Finance SDK 返回的会话内容为空。

What it means

After GetChatData calls the native Finance SDK and it reports success, the client reads the slice content. If the SDK returns null/empty JSON for the slice, it throws InvalidDataException because an empty payload cannot represent a valid chat-data result.

Solutions

  1. Verify the WeWork Finance native SDK binary version matches the SDK the .NET wrapper targets and reinstall if needed
  2. Check network/proxy settings in MsgAuditFinanceOptions (proxy/proxyPassword) and corporate firewall rules to qyapi.weixin.qq.com
  3. Regenerate/retry the pull from the last known sequence; check the seq cursor is valid
  4. Enable/inspect ThrowIfNativeError output — a zero code with empty content usually indicates an SDK-side issue to report upstream

Example fix

// before
var slice = client.NewSlice(...); // slice content empty -> exception
// after
var result = client.GetChatData(seq, 1000);
if (result == null || result.ChatData == null || result.ChatData.Count == 0)
{
    _logger.LogWarning("No chat data for seq {Seq}; will retry later", seq);
    return;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// check SDK load and options before pulling
if (!NativeSdkProbe.IsLoaded()) throw new InvalidOperationException("Finance SDK not loaded");

Try / catch

try { var data = client.GetChatData(seq, 1000); } catch (InvalidDataException ex) { log.Warn(ex, "Empty finance slice at seq {Seq}", seq); await Task.Delay(backoff); ScheduleRetry(seq); }

Prevention

When it happens

Trigger: Native SDK GetSliceContent returns empty for a slice — e.g. corrupted slice handle, SDK/environment mismatch, proxy/network interference truncating the response, or the slice being freed before read.

Common situations: Mismatched native SDK binary versions on the host; running on an OS/arch where the SDK misbehaves; expired/invalid chatdata causing the SDK to return nothing without a nonzero error code.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/d982a9470ca3da38. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:101

            {
                throw new ArgumentOutOfRangeException(nameof(limit), "单次拉取条数必须介于 1 和 1000 之间。");
            }

            lock (_syncRoot)
            {
                ThrowIfDisposed();
                var slice = _nativeApi.NewSlice();
                EnsureNativeHandle(slice, "NewSlice");
                try
                {
                    var errorCode = _nativeApi.GetChatData(_sdk, sequence, limit, _proxy,
                        _proxyPassword, _timeoutSeconds, slice);
                    ThrowIfNativeError(errorCode, "GetChatData");

                    var json = _nativeApi.GetSliceContent(slice);
                    if (string.IsNullOrWhiteSpace(json))
                    {
                        throw new InvalidDataException("Finance SDK 返回的会话内容为空。");
                    }

                    var result = JsonSerializer.Deserialize(json,
                        MsgAuditFinanceJsonSerializerContext.Default.MsgAuditFinanceChatDataResult);
                    if (result == null)
                    {
                        throw new InvalidDataException("无法解析 Finance SDK 返回的会话内容 JSON。");
                    }

                    result.raw_json = json;
                    return result;
                }
                finally
                {
                    _nativeApi.FreeSlice(slice);
                }
            }
        }

View on GitHub (pinned to be573f6f94)