{"record":{"id":"bdfb20cc9ccc6012","repo":"JeffreySu/WeiXinMPSDK","slug":"msgauditfinanceclient-bdfb20","errorCode":null,"errorMessage":"参数不能为空。","messagePattern":"参数不能为空。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":293,"sourceCode":"            if (options == null)\n            {\n                throw new ArgumentNullException(nameof(options));\n            }\n\n            ValidateRequiredText(options.CorpId, nameof(options.CorpId));\n            ValidateRequiredText(options.Secret, nameof(options.Secret));\n            if (options.TimeoutSeconds <= 0)\n            {\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        }","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L275-L311","documentation":"ValidateRequiredText rejects null, empty, or whitespace-only strings for mandatory parameters, throwing ArgumentException with message '参数不能为空。' and the offending parameter name. It guards sdkFileId, corpId, secret, and other required text fields across DecryptData, GetMediaData, DownloadMedia, and ValidateOptions.","triggerScenarios":"Passing an empty or whitespace string as sdkFileId to GetMediaData/DownloadMedia, or constructing the client with empty CorpId/Secret, or DecryptData receiving an empty key/buffer string.","commonSituations":"Decrypted message JSON missing the sdkfileid field so an empty string is propagated, environment variables for corp credentials unset, or trimming producing empty strings from placeholder config values.","solutions":["Ensure sdkFileid is read from the decrypted message JSON before calling GetMediaData/DownloadMedia","Set valid CorpId and Secret in MsgAuditFinanceOptions before constructing the client","Validate inputs with string.IsNullOrWhiteSpace before invoking the API"],"exampleFix":"// before\nstring sdkFileId = msg[\"sdkfileid\"]?.ToString(); // may be null/empty\nclient.DownloadMedia(sdkFileId, stream);\n// after\nstring sdkFileId = msg[\"sdkfileid\"]?.ToString();\nif (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException(\"message has no sdkfileid\");\nclient.DownloadMedia(sdkFileId, stream);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException(\"sdkFileId must come from a decrypted message\");\nif (string.IsNullOrWhiteSpace(options.CorpId) || string.IsNullOrWhiteSpace(options.Secret)) throw new InvalidOperationException(\"CorpId and Secret are required\");","typeGuard":"bool HasText(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { client.DownloadMedia(sdkFileId, stream); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"参数不能为空\")) { /* identify ex.ParamName and supply the missing value */ }","preventionTips":["Always extract sdkfileid from the decrypted message JSON and check it before use","Validate credentials at startup with a smoke test call","Avoid propagating strings from config without IsNullOrWhiteSpace checks"],"tags":["csharp","empty-string","validation","weixin-work"],"backgroundTag":"empty-required-field","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"}