JeffreySu/WeiXinMPSDK · error · ArgumentOutOfRangeException
原生 SDK 网络请求超时时间必须大于 0 秒。
Error message
原生 SDK 网络请求超时时间必须大于 0 秒。
What it means
ValidateOptions enforces that MsgAuditFinanceOptions.TimeoutSeconds is strictly positive because the value is passed to the native Finance SDK as its network request timeout. Zero or negative values are rejected with ArgumentOutOfRangeException.
Solutions
- Set TimeoutSeconds to a positive value in MsgAuditFinanceOptions (e.g. 30)
- Check the config source that populates TimeoutSeconds and fix the parsing/defaulting
- If relying on defaults, ensure the options object is initialized, not default(MsgAuditFinanceOptions)
Example fix
// before
var options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret }; // TimeoutSeconds = 0
// after
var options = new MsgAuditFinanceOptions { CorpId = corpId, Secret = secret, TimeoutSeconds = 30 }; Defensive patterns
Strategy: validation
Validate before calling
if (options.TimeoutSeconds <= 0) throw new InvalidOperationException("TimeoutSeconds must be positive, e.g. 30"); Try / catch
try { var client = new MsgAuditFinanceClient(options); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "options.TimeoutSeconds") { options.TimeoutSeconds = 30; /* retry */ } Prevention
- Give TimeoutSeconds a nonzero default in option classes/config binding
- Clamp parsed config values: Math.Max(1, parsed)
- Document that 0 does not mean 'infinite timeout' for this SDK
When it happens
Trigger: Constructing MsgAuditFinanceClient with options whose TimeoutSeconds is 0 or negative — typically from a default(T) struct, a misparsed config value, or an explicit 0 intended to mean 'no timeout'.
Common situations: App config or environment variable yielding 0 after int.Parse, a struct default initialized without setting TimeoutSeconds, or developers assuming 0 disables the timeout (it does not).
Related errors
- ArgumentNullException (options is null)
- AppId 不能为空。
- 此appId(…
- AppId 不能为空。
- 超时时间必须大于 0,或使用 Timeout.Infinite。
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/3fa751d677b47fea.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:284
private static IMsgAuditFinanceNativeApi CreateNativeApi(MsgAuditFinanceOptions options)
{
ValidateOptions(options);
return new MsgAuditFinanceNativeApi(options.LibraryPath);
}
private static void ValidateOptions(MsgAuditFinanceOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
ValidateRequiredText(options.CorpId, nameof(options.CorpId));
ValidateRequiredText(options.Secret, nameof(options.Secret));
if (options.TimeoutSeconds <= 0)
{
throw new ArgumentOutOfRangeException(nameof(options.TimeoutSeconds),
"原生 SDK 网络请求超时时间必须大于 0 秒。");
}
}
private static void ValidateRequiredText(string value, string parameterName)
{
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} 操作返回了空指针。");
}View on GitHub (pinned to be573f6f94)