{"record":{"id":"2a6eeddc15e441a9","repo":"JeffreySu/WeiXinMPSDK","slug":"finance-sdk-operation","errorCode":null,"errorMessage":"Finance SDK 的 {operation} 操作返回了空指针。","messagePattern":"Finance SDK 的 (.+?) 操作返回了空指针。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":301,"sourceCode":"            {\n                throw new ArgumentOutOfRangeException(nameof(options.TimeoutSeconds),\n                    \"原生 SDK 网络请求超时时间必须大于 0 秒。\");\n            }\n        }\n\n        private static void ValidateRequiredText(string value, string parameterName)\n        {\n            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        }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L283-L319","documentation":"The native Finance SDK's Init/GetChatData/GetMediaData/DecryptData return IntPtr handles; EnsureNativeHandle throws InvalidOperationException with 'Finance SDK 的 {operation} 操作返回了空指针。' when an operation returns IntPtr.Zero, meaning the native call produced no valid handle/data pointer.","triggerScenarios":"A native SDK call (Init, GetChatData, GetMediaData, DecryptData) returns IntPtr.Zero — typically after native initialization failure, wrong library path, or the SDK returning null output on error without the error code path firing.","commonSituations":"Running without the correct architecture-matched native library, SDK out-of-memory, invalid credentials causing Init to yield a zero handle, or platform issues (e.g. missing libcurl dependencies on Linux).","solutions":["Confirm LibraryPath points to the correct architecture-matched official libWeWorkFinanceSdk (x64) and that it loads without missing native dependencies","Verify CorpId/Secret are correct so native Init succeeds","Check the Linux/Windows environment has all runtime dependencies for the native SDK (e.g. libcurl, openssl)","Re-run with logging around the failing operation to capture the native error before the null handle"],"exampleFix":"// before\nvar options = new MsgAuditFinanceOptions { LibraryPath = \"/opt/lib/libWeWorkFinanceSdk.so\" }; // wrong arch\n// after\nvar options = new MsgAuditFinanceOptions { LibraryPath = \"/opt/lib/x64/libWeWorkFinanceSdk_C.so\" }; // match process architecture","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify native library loads and credentials init succeed before batch processing\nusing var probe = new MsgAuditFinanceClient(options); // constructor initializes native SDK","typeGuard":null,"tryCatchPattern":"try { var data = client.GetChatData(...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"返回了空指针\")) { /* native call failed: check library arch/deps and credentials, then recreate client */ }","preventionTips":["Match native library architecture to the process (x64 vs x86)","Install native runtime dependencies (libcurl, openssl) on Linux hosts","Verify credentials before bulk jobs; treat this error as native initialization/data failure","Wrap long-running jobs with client recreation on failure"],"tags":["csharp","native-sdk","pinvoke","null-pointer","weixin-work"],"backgroundTag":"module-init-failed","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"}