JeffreySu/WeiXinMPSDK · error · ArgumentException

参数不能为空。

Error message

参数不能为空。

What it means

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.

Solutions

  1. Ensure sdkFileid is read from the decrypted message JSON before calling GetMediaData/DownloadMedia
  2. Set valid CorpId and Secret in MsgAuditFinanceOptions before constructing the client
  3. Validate inputs with string.IsNullOrWhiteSpace before invoking the API

Example fix

// before
string sdkFileId = msg["sdkfileid"]?.ToString(); // may be null/empty
client.DownloadMedia(sdkFileId, stream);
// after
string sdkFileId = msg["sdkfileid"]?.ToString();
if (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException("message has no sdkfileid");
client.DownloadMedia(sdkFileId, stream);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(sdkFileId)) throw new InvalidOperationException("sdkFileId must come from a decrypted message");
if (string.IsNullOrWhiteSpace(options.CorpId) || string.IsNullOrWhiteSpace(options.Secret)) throw new InvalidOperationException("CorpId and Secret are required");

Type guard

bool HasText(string? s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try { client.DownloadMedia(sdkFileId, stream); }
catch (ArgumentException ex) when (ex.Message.Contains("参数不能为空")) { /* identify ex.ParamName and supply the missing value */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/bdfb20cc9ccc6012. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/MsgAudit/MsgAuditFinanceClient.cs:293

            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} 操作返回了空指针。");
            }
        }

        private static void ThrowIfNativeError(int errorCode, string operation)
        {
            if (errorCode != 0)
            {
                throw new MsgAuditFinanceException(errorCode, operation);
            }
        }

View on GitHub (pinned to be573f6f94)