{"record":{"id":"25a313d5cdb08abf","repo":"JeffreySu/WeiXinMPSDK","slug":"finance-sdk-msgauditfinanceclient","errorCode":null,"errorMessage":"Finance SDK 尚未完成媒体下载，但没有返回可继续使用的新索引缓冲区。","messagePattern":"Finance SDK 尚未完成媒体下载，但没有返回可继续使用的新索引缓冲区。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":233,"sourceCode":"            while (true)\n            {\n                cancellationToken.ThrowIfCancellationRequested();\n                var chunk = GetMediaData(sdkFileId, indexBuffer);\n                if (chunk.data.Length > 0)\n                {\n                    destination.Write(chunk.data, 0, chunk.data.Length);\n                    totalBytes = checked(totalBytes + chunk.data.LongLength);\n                }\n\n                if (chunk.is_finished)\n                {\n                    return totalBytes;\n                }\n\n                if (string.IsNullOrEmpty(chunk.next_index_buffer) ||\n                    string.Equals(chunk.next_index_buffer, indexBuffer, StringComparison.Ordinal))\n                {\n                    throw new InvalidDataException(\n                        \"Finance SDK 尚未完成媒体下载，但没有返回可继续使用的新索引缓冲区。\");\n                }\n\n                indexBuffer = chunk.next_index_buffer;\n            }\n        }\n\n        /// <summary>\n        /// 销毁官方 SDK 实例并释放动态库句柄。\n        /// </summary>\n        public void Dispose()\n        {\n            lock (_syncRoot)\n            {\n                if (_disposed)\n                {\n                    return;\n                }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L215-L251","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nusing var client = new MsgAuditFinanceClient(options);\nvar first = client.GetChatData(...);\nusing var client2 = new MsgAuditFinanceClient(options); // new native instance\nclient2.DownloadMedia(sdkFileId, stream);\n// after\nusing var client = new MsgAuditFinanceClient(options);\nvar first = client.GetChatData(...);\nclient.DownloadMedia(sdkFileId, stream); // same instance throughout","handlingStrategy":"retry","validationCode":"// Validate sdkfileid exists before download\nif (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException(\"missing sdkfileid\");","typeGuard":"bool IsDownloadable(string? id) => !string.IsNullOrWhiteSpace(id);","tryCatchPattern":"try { client.DownloadMedia(sdkFileId, stream); }\ncatch (InvalidDataException) { stream.SetLength(0); /* reset and retry with same client instance */ client.DownloadMedia(sdkFileId, stream); }","preventionTips":["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"],"tags":["csharp","native-sdk","download","weixin-work","invalid-data"],"backgroundTag":"unexpected-response-shape","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}