JeffreySu/WeiXinMPSDK · error · InvalidDataException
Finance SDK 尚未完成媒体下载,但没有返回可继续使用的新索引缓冲区。
Error message
Finance SDK 尚未完成媒体下载,但没有返回可继续使用的新索引缓冲区。
What it means
During chunked media download, the native Finance SDK signals progress via a next_index_buffer. If a chunk is not finished (is_finished == false) but the SDK returns an empty index buffer or one identical to the current one, the loop would never progress, so the library throws InvalidDataException to prevent an infinite loop.
Solutions
- Retry the DownloadMedia call; transient SDK issues often resolve on retry
- Verify the sdkfileid comes from the decrypted chat message of the same corp and SDK instance
- Ensure you use one MsgAuditFinanceClient (one native SDK instance) for the whole download — do not recreate the client between chunks
- Upgrade to the latest official libWeWorkFinanceSdk native library
Example fix
// before using var client = new MsgAuditFinanceClient(options); var first = client.GetChatData(...); using var client2 = new MsgAuditFinanceClient(options); // new native instance client2.DownloadMedia(sdkFileId, stream); // after using var client = new MsgAuditFinanceClient(options); var first = client.GetChatData(...); client.DownloadMedia(sdkFileId, stream); // same instance throughout
Defensive patterns
Strategy: retry
Validate before calling
// Validate sdkfileid exists before download
if (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException("missing sdkfileid"); Type guard
bool IsDownloadable(string? id) => !string.IsNullOrWhiteSpace(id);
Try / catch
try { client.DownloadMedia(sdkFileId, stream); }
catch (InvalidDataException) { stream.SetLength(0); /* reset and retry with same client instance */ client.DownloadMedia(sdkFileId, stream); } Prevention
- Reuse one client/native instance for all chunks of a download
- Keep the official native SDK library up to date
- Log chunk.next_index_buffer progression to diagnose stalled downloads
When it happens
Trigger: DownloadMedia receives a GetMediaData chunk where is_finished is false and next_index_buffer is null, empty, or byte-for-byte identical to the previous index buffer.
Common situations: Native SDK version mismatches or bugs where the cursor does not advance, corrupted sdkfileid values, intermittent SDK failures mid-download, or passing an index buffer across unrelated SDK instances.
Related errors
- Finance SDK 的 操作返回了空指针。
- MsgAuditFinanceException (native SDK returned non-zero…
- ArgumentNullException (destination is null)
- 目标流必须可写。
- ArgumentNullException (options is null)
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/25a313d5cdb08abf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:233
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
var chunk = GetMediaData(sdkFileId, indexBuffer);
if (chunk.data.Length > 0)
{
destination.Write(chunk.data, 0, chunk.data.Length);
totalBytes = checked(totalBytes + chunk.data.LongLength);
}
if (chunk.is_finished)
{
return totalBytes;
}
if (string.IsNullOrEmpty(chunk.next_index_buffer) ||
string.Equals(chunk.next_index_buffer, indexBuffer, StringComparison.Ordinal))
{
throw new InvalidDataException(
"Finance SDK 尚未完成媒体下载,但没有返回可继续使用的新索引缓冲区。");
}
indexBuffer = chunk.next_index_buffer;
}
}
/// <summary>
/// 销毁官方 SDK 实例并释放动态库句柄。
/// </summary>
public void Dispose()
{
lock (_syncRoot)
{
if (_disposed)
{
return;
}View on GitHub (pinned to be573f6f94)