JeffreySu/WeiXinMPSDK · error · ArgumentNullException
必须指定待删除的分账接收方
Error message
必须指定待删除的分账接收方
What it means
TenpayV3ProfitShareingRemoveReceiverRequestData's constructor requires a Receiver object identifying the profit-sharing receiver to delete. Passing null throws an ArgumentNullException with this message.
Solutions
- Build a Receiver with at least Type and Account set, then pass it to the constructor.
- Check argument order/positions — a shifted null argument may be landing on the receiver parameter.
- Skip the remove call when the receiver record doesn't exist instead of passing null.
Example fix
// before
var data = new TenpayV3ProfitShareingRemoveReceiverRequestData(key, appid, mchid, null, version);
// after
var receiver = new Receiver { Type = "MERCHANT_ID", Account = "190001001" };
var data = new TenpayV3ProfitShareingRemoveReceiverRequestData(key, appid, mchid, receiver, version); Defensive patterns
Strategy: validation
Validate before calling
// C#
if (receiver is null)
throw new InvalidOperationException("Receiver must be provided to remove a profit-sharing receiver"); Type guard
bool CanRemove(Receiver r) => r is not null && !string.IsNullOrWhiteSpace(r.Account);
Try / catch
try { var data = new TenpayV3ProfitShareingRemoveReceiverRequestData(key, appid, mchid, receiver, version); }
catch (ArgumentNullException ex) when (ex.Message.Contains("分账接收方")) { log.LogWarning("RemoveReceiver skipped: receiver was null"); } Prevention
- Verify constructor argument order to avoid a null landing on receiver
- Check receiver existence before issuing a remove call
- Treat already-deleted receivers as no-op instead of null
When it happens
Trigger: new TenpayV3ProfitShareingRemoveReceiverRequestData(...) with receiver = null when removing a 分账接收方.
Common situations: Trying to remove a receiver whose record was already deleted locally, so the lookup returned null, or misordering constructor arguments so the wrong (null) value lands in the receiver slot.
Related errors
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/376507610c36368f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Entities/Request/TenpayV3ProfitShareingRequestData.cs:682
/// <param name="nonceStr"></param>
/// <param name="receiver">需要删除的的分账接收方对象</param>
/// <param name="version">统一下单接口参数,参考:https://pay.weixin.qq.com/wiki/doc/api/danpin.php?chapter=9_203&index=6</param>
public TenpayV3ProfitShareingRemoveReceiverRequestData(
string appId, string mchId, string subappid, string submchid, string key, string nonceStr,
TenpayV3ProfitShareing_ReceiverInfo receiver, string version = null
)
{
AppId = appId;
MchId = mchId;
NonceStr = nonceStr;
Key = key;
SubAppId = subappid;
SubMchId = submchid;
Receiver = receiver;
Version = version;
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.SetParameterWhenNotNull("version", Version);
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)