JeffreySu/WeiXinMPSDK · error · ArgumentNullException

必须指定待分账的接收方列表

Error message

必须指定待分账的接收方列表

What it means

The TenpayV3ProtfitSharingRequestData constructor requires a non-empty receivers array (the list of profit-sharing receivers for a WeChat Pay v3 分账 request). If receivers is null or an empty array, an ArgumentNullException with this message is thrown — note the message is passed as paramName, which is unconventional but the check itself is intentional.

Solutions

  1. Build at least one receiver entry (type, account, amount/description) and pass it to the constructor.
  2. Guard at the call site: skip or reject profit-sharing calls when the receiver list is empty.
  3. Fix upstream logic that produces an empty receivers array (e.g. filtering by ratio > 0 removing all entries).

Example fix

// before
var data = new TenpayV3ProtfitSharingRequestData(appid, mchid, null, transactionId, outOrderNo, ...);
// after
var receivers = new[] { new Receiver { Type = "MERCHANT_ID", Account = "190001001", Amount = 100, Description = "分账" } };
var data = new TenpayV3ProtfitSharingRequestData(appid, mchid, receivers, transactionId, outOrderNo, ...);
Defensive patterns

Strategy: validation

Validate before calling

// C#
if (receivers is null || receivers.Length == 0)
    throw new InvalidOperationException("Profit-sharing needs at least one receiver");

Type guard

bool HasReceivers(Receiver[] r) => r is { Length: > 0 };

Try / catch

try { var data = new TenpayV3ProtfitSharingRequestData(..., receivers, ...); }
catch (ArgumentNullException ex) when (ex.Message.Contains("接收方列表")) { log.LogWarning("No receivers configured for order {OrderNo}", outOrderNo); }

Prevention

When it happens

Trigger: Creating a profit-sharing request via new TenpayV3ProtfitSharingRequestData(...) and passing null or new Receiver[0] for the receivers parameter.

Common situations: Order had no receivers configured in the merchant system, or the receivers list was filtered to empty before construction, or a copy/paste left the array argument empty in sample-driven code.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Entities/Request/TenpayV3ProfitShareingRequestData.cs:167

        /// <param name="receivers">分账接收方列表,此对象通过Json格式传输</param>
        public TenpayV3ProtfitSharingRequestData(
            string appId, string mchId, string subappid, string submchid, string key, string nonceStr,
            string transactionId,
            string outOrderNo,
            TenpayV3ProfitShareingRequestData_ReceiverInfo[] receivers
        )
        {
            AppId = appId;
            MchId = mchId;
            NonceStr = nonceStr;
            Key = key;
            SubAppId = subappid;
            SubMchId = submchid;
            Receivers = receivers;

            if (Receivers == null || Receivers.Length == 0)
            {
                throw new ArgumentNullException("必须指定待分账的接收方列表");
            }
            TransactionId = transactionId;
            OutOrderNo = outOrderNo;


            #region 设置RequestHandler

            //创建支付应答对象
            PackageRequestHandler = new RequestHandler(null);
            //初始化
            PackageRequestHandler.Init();

            //设置package订单参数
            //以下设置顺序按照官方文档排序,方便维护:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
            PackageRequestHandler.SetParameter("appid", this.AppId);                       //公众账号ID
            PackageRequestHandler.SetParameter("mch_id", this.MchId);                      //商户号
            PackageRequestHandler.SetParameterWhenNotNull("sub_appid", this.SubAppId);     //子商户公众账号ID
            PackageRequestHandler.SetParameterWhenNotNull("sub_mch_id", this.SubMchId);    //子商户号

View on GitHub (pinned to be573f6f94)