{"record":{"id":"c73fd035a53ae4cc","repo":"JeffreySu/WeiXinMPSDK","slug":"msgauditfinanceexception-native-sdk-returned-non-zero-error","errorCode":null,"errorMessage":"MsgAuditFinanceException (native SDK returned non-zero error code)","messagePattern":"MsgAuditFinanceException \\(native SDK returned non-zero error code\\)","errorType":"error_code","errorClass":"MsgAuditFinanceException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":309,"sourceCode":"            if (string.IsNullOrWhiteSpace(value))\n            {\n                throw new ArgumentException(\"参数不能为空。\", parameterName);\n            }\n        }\n\n        private static void EnsureNativeHandle(IntPtr handle, string operation)\n        {\n            if (handle == IntPtr.Zero)\n            {\n                throw new InvalidOperationException($\"Finance SDK 的 {operation} 操作返回了空指针。\");\n            }\n        }\n\n        private static void ThrowIfNativeError(int errorCode, string operation)\n        {\n            if (errorCode != 0)\n            {\n                throw new MsgAuditFinanceException(errorCode, operation);\n            }\n        }\n\n        private void ThrowIfDisposed()\n        {\n            if (_disposed)\n            {\n                throw new ObjectDisposedException(nameof(MsgAuditFinanceClient));\n            }\n        }\n\n        private void ReleaseResources(bool disposing)\n        {\n            if (_disposed)\n            {\n                return;\n            }\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L291-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ntry { var data = client.GetChatData(seq, limit, proxy, passwd, timeout); }\ncatch (Exception ex) { log.Error(ex); }\n// after\ntry { var data = client.GetChatData(seq, limit, proxy, passwd, timeout); }\ncatch (MsgAuditFinanceException ex) { log.Error($\"native op {ex.Operation} failed, code {ex.ErrorCode}\"); /* handle per code: retry on transient, abort on auth */ }","handlingStrategy":"try-catch","validationCode":"// Ensure permissions and credentials before calling\nif (string.IsNullOrWhiteSpace(options.Secret) || string.IsNullOrWhiteSpace(options.CorpId)) throw new InvalidOperationException(\"check finance audit credentials\");","typeGuard":null,"tryCatchPattern":"try { var data = client.GetChatData(...); }\ncatch (MsgAuditFinanceException ex) { switch (ex.ErrorCode) { /* retry transient codes with backoff; abort and alert on auth/permission codes */ } }","preventionTips":["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"],"tags":["csharp","native-sdk","error-code","weixin-work","finance"],"backgroundTag":"api-error-response","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"}