JeffreySu/WeiXinMPSDK · error · ArgumentNullException
必须指定待添加的分账接收方
Error message
必须指定待添加的分账接收方
What it means
TenpayV3ProfitShareingAddReceiverRequestData's constructor requires a Receiver object describing the profit-sharing receiver to add. Passing null throws an ArgumentNullException with this message; WeChat Pay's add-receiver API cannot be called without a receiver payload.
Solutions
- Construct a valid Receiver (type MERCHANT_ID/PERSONAL_OPENID, account, name, relation type) before calling the constructor.
- Null-check the receiver object at the call site.
- Verify the source of the receiver record — the upstream lookup returning null is usually the root cause.
Example fix
// before
Receiver receiver = repo.Find(account); // may be null
var data = new TenpayV3ProfitShareingAddReceiverRequestData(key, appid, mchid, receiver);
// after
var receiver = repo.Find(account) ?? throw new InvalidOperationException($"receiver {account} not configured");
var data = new TenpayV3ProfitShareingAddReceiverRequestData(key, appid, mchid, receiver); Defensive patterns
Strategy: validation
Validate before calling
// C#
if (receiver is null)
throw new InvalidOperationException("Receiver must be loaded before calling AddReceiver"); Type guard
bool IsValidReceiver(Receiver r) => r is not null && !string.IsNullOrWhiteSpace(r.Account);
Try / catch
try { var data = new TenpayV3ProfitShareingAddReceiverRequestData(key, appid, mchid, receiver); }
catch (ArgumentNullException ex) when (ex.Message.Contains("分账接收方")) { log.LogWarning("AddReceiver skipped: receiver record missing"); } Prevention
- Load and verify receiver config before constructing request data
- Use nullable reference types to catch unassigned receiver properties
- Keep receiver records in sync with WeChat merchant platform
When it happens
Trigger: new TenpayV3ProfitShareingAddReceiverRequestData(...) with receiver = null when trying to register a 分账接收方 (merchant or personal payee).
Common situations: Receiver details loaded from config/database returned null (account not yet onboarded), or an uninitialized property was passed before population.
Related errors
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/8c2a56aa8f9c92b9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Entities/Request/TenpayV3ProfitShareingRequestData.cs:560
/// <param name="key"></param>
/// <param name="nonceStr"></param>
/// <param name="receiver">新添加的分账接收方对象
/// </param>
public TenpayV3ProfitShareingAddReceiverRequestData(
string appId, string mchId, string subappid, string submchid, string key, string nonceStr,
TenpayV3ProfitShareingAddReceiverRequestData_ReceiverInfo receiver
)
{
AppId = appId;
MchId = mchId;
NonceStr = nonceStr;
Key = key;
SubAppId = subappid;
SubMchId = submchid;
Receiver = receiver;
if (Receiver == null)
{
throw new ArgumentNullException("必须指定待添加的分账接收方");
}
#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); //子商户号
PackageRequestHandler.SetParameter("nonce_str", this.NonceStr); //随机字符串
PackageRequestHandler.SetParameter("sign_type", this.SignType); //签名类型,默认为MD5
View on GitHub (pinned to be573f6f94)