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

  1. Read MsgAuditFinanceException.ErrorCode and consult the official WeWork Finance SDK error code table
  2. Verify CorpId and Secret and that 会话内容存档 (message audit) is enabled with proper permissions
  3. Check network connectivity to WeWork servers and respect rate limits (add retry with backoff)
  4. 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

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


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)