JeffreySu/WeiXinMPSDK · error · MsgAuditFinanceException
MsgAuditFinanceException (native SDK returned non-zero…
Error message
MsgAuditFinanceException (native SDK returned non-zero error code)
What it means
ThrowIfNativeError translates any non-zero return code from the native Finance SDK into a MsgAuditFinanceException carrying the native error code and operation name. This is the wrapper's way of surfacing native SDK failures (auth errors, network errors, rate limits, invalid parameters) from GetChatData, DecryptData, and GetMediaData.
Solutions
- Read MsgAuditFinanceException.ErrorCode and consult the official WeWork Finance SDK error code table
- Verify CorpId and Secret and that 会话内容存档 (message audit) is enabled with proper permissions
- Check network connectivity to WeWork servers and respect rate limits (add retry with backoff)
- Log the operation name from the exception to identify which native call failed
Example fix
// before
try { var data = client.GetChatData(seq, limit, proxy, passwd, timeout); }
catch (Exception ex) { log.Error(ex); }
// after
try { var data = client.GetChatData(seq, limit, proxy, passwd, timeout); }
catch (MsgAuditFinanceException ex) { log.Error($"native op {ex.Operation} failed, code {ex.ErrorCode}"); /* handle per code: retry on transient, abort on auth */ } Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure permissions and credentials before calling
if (string.IsNullOrWhiteSpace(options.Secret) || string.IsNullOrWhiteSpace(options.CorpId)) throw new InvalidOperationException("check finance audit credentials"); Try / catch
try { var data = client.GetChatData(...); }
catch (MsgAuditFinanceException ex) { switch (ex.ErrorCode) { /* retry transient codes with backoff; abort and alert on auth/permission codes */ } } Prevention
- Map native error codes to retry/no-retry policies in one place
- Enable 会话内容存档 permissions and use correct vault credentials
- Implement backoff for rate-limit codes
- Monitor ErrorCode trends to catch credential/network issues early
When it happens
Trigger: GetChatData/GetMediaData/DecryptData where the native SDK returns a non-zero code — e.g. expired or wrong Secret, seq out of range, rate limiting, or network failure inside the native layer.
Common situations: Wrong corp credentials, chat archive permissions not enabled for the corp account, exceeding QPS limits, network egress blocked from the server, or passing an invalid seq/timestamp.
Related errors
- Finance SDK 尚未完成媒体下载,但没有返回可继续使用的新索引缓冲区。
- Finance SDK 的 操作返回了空指针。
- ArgumentNullException (destination is null)
- 目标流必须可写。
- ArgumentNullException (options is null)
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/c73fd035a53ae4cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:309
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("参数不能为空。", parameterName);
}
}
private static void EnsureNativeHandle(IntPtr handle, string operation)
{
if (handle == IntPtr.Zero)
{
throw new InvalidOperationException($"Finance SDK 的 {operation} 操作返回了空指针。");
}
}
private static void ThrowIfNativeError(int errorCode, string operation)
{
if (errorCode != 0)
{
throw new MsgAuditFinanceException(errorCode, operation);
}
}
private void ThrowIfDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(nameof(MsgAuditFinanceClient));
}
}
private void ReleaseResources(bool disposing)
{
if (_disposed)
{
return;
}
View on GitHub (pinned to be573f6f94)