{"record":{"id":"db3ba9d88b772c21","repo":"JeffreySu/WeiXinMPSDK","slug":"1-1000","errorCode":null,"errorMessage":"单次拉取条数必须介于 1 和 1000 之间。","messagePattern":"单次拉取条数必须介于 1 和 1000 之间。","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs","lineNumber":84,"sourceCode":"            {\n                ReleaseResources(false);\n                throw;\n            }\n        }\n\n        /// <summary>\n        /// 拉取加密会话记录。\n        /// </summary>\n        /// <param name=\"sequence\">起始消息序号；返回 sequence 之后的消息，首次调用传 0。</param>\n        /// <param name=\"limit\">单次拉取条数，必须介于 1 和 1000 之间。</param>\n        /// <returns>包含加密随机密钥、消息密文和完整原始 JSON 的强类型结果。</returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"limit\"/> 不在官方允许范围内。</exception>\n        /// <exception cref=\"MsgAuditFinanceException\">原生 SDK 返回非零错误码。</exception>\n        public MsgAuditFinanceChatDataResult GetChatData(ulong sequence, uint limit = 1000)\n        {\n            if (limit == 0 || limit > 1000)\n            {\n                throw new ArgumentOutOfRangeException(nameof(limit), \"单次拉取条数必须介于 1 和 1000 之间。\");\n            }\n\n            lock (_syncRoot)\n            {\n                ThrowIfDisposed();\n                var slice = _nativeApi.NewSlice();\n                EnsureNativeHandle(slice, \"NewSlice\");\n                try\n                {\n                    var errorCode = _nativeApi.GetChatData(_sdk, sequence, limit, _proxy,\n                        _proxyPassword, _timeoutSeconds, slice);\n                    ThrowIfNativeError(errorCode, \"GetChatData\");\n\n                    var json = _nativeApi.GetSliceContent(slice);\n                    if (string.IsNullOrWhiteSpace(json))\n                    {\n                        throw new InvalidDataException(\"Finance SDK 返回的会话内容为空。\");\n                    }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs#L66-L102","documentation":"MsgAuditFinanceClient.GetChatData pulls session audit data from the WeCom Finance SDK. WeCom officially allows 1–1000 records per pull, so the client rejects limit==0 or limit>1000 with ArgumentOutOfRangeException before touching the native SDK.","triggerScenarios":"Calling GetChatData(sequence, limit) with limit = 0, an unbounded value (e.g. int.MaxValue cast to uint), or a computed limit like remaining-count that overflows the allowed range.","commonSituations":"Using a paging loop where the last-page size calculation yields 0; hardcoding a large batch size for 'fewer calls'; copying a limit from another API with different caps.","solutions":["Clamp the limit: limit = Math.Clamp(limit, 1, 1000)","Fix paging logic so the final call uses a positive limit and stops when nothing remains","Keep 1000 as the default; only pass explicit limits within 1–1000"],"exampleFix":"// before\nclient.GetChatData(sequence, 5000);\n// after\nvar clamped = Math.Clamp(limit, 1, 1000);\nclient.GetChatData(sequence, clamped);","handlingStrategy":"validation","validationCode":"if (limit == 0 || limit > 1000) throw new ArgumentException(\"limit must be 1..1000\", nameof(limit));\nclient.GetChatData(sequence, limit);","typeGuard":"static bool IsValidLimit(uint limit) => limit is >= 1 and <= 1000;","tryCatchPattern":"try { var data = client.GetChatData(seq, limit); } catch (ArgumentOutOfRangeException ex) { log.Error(\"limit out of range: {0}\", ex.ParamName); }","preventionTips":["Clamp computed page sizes with Math.Clamp(limit, 1, 1000)","Break loops when the API returns fewer records than requested","Never reuse limits from other APIs with different caps"],"tags":["validation","range","msgaudit","wecom"],"backgroundTag":"value-out-of-range","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"}