JeffreySu/WeiXinMPSDK · error · WeixinException
WeixinPayInfoCollection尚未注册Partner:
Error message
WeixinPayInfoCollection尚未注册Partner:{0} What it means
TenPayInfoCollection (V2) throws this WeixinException from its string indexer when the requested partner key is not present in the registered TenPayInfo entries. The collection must be pre-populated (via Register) before indexed access; the indexer is a hard-fail lookup, not a dictionary TryGetValue.
Solutions
- Register the partner before use: new TenPayInfo(...) and TenPayInfoCollection.Register(tenPayInfo) at application startup.
- Verify the exact partner key used in the indexer matches the registered Partner value (case and whitespace).
- Check ContainsKey or TryGetValue-style access before indexing in multi-tenant code.
- Confirm the registration code actually runs in the failing environment (Startup/Global.asax/Program main path).
Example fix
// before
var tenPayInfo = TenPayInfoCollection.Data[partnerId]; // throws if unregistered
// after
if (TenPayInfoCollection.Data.ContainsKey(partnerId))
{
var tenPayInfo = TenPayInfoCollection.Data[partnerId];
}
else
{
TenPayInfoCollection.Register(new TenPayInfo(partnerId, appId, appSecret, tenPayPartnerKey, tenPayNotifyUrl));
} Defensive patterns
Strategy: try-catch
Validate before calling
bool partnerRegistered = TenPayInfoCollection.Data.ContainsKey(partnerId);
if (!partnerRegistered) throw new InvalidOperationException($"Partner '{partnerId}' is not registered. Call TenPayInfoCollection.Register at startup."); Type guard
bool TryGetTenPayInfo(string partnerId, out TenPayInfo info)
{
if (TenPayInfoCollection.Data.ContainsKey(partnerId)) { info = TenPayInfoCollection.Data[partnerId]; return true; }
info = null; return false;
} Try / catch
try { var info = TenPayInfoCollection.Data[partnerId]; }
catch (WeixinException ex) when (ex.Message.StartsWith("WeixinPayInfoCollection尚未注册Partner"))
{
log.Error(ex.Message);
throw new InvalidOperationException("Register the TenPay V2 partner at application startup.", ex);
} Prevention
- Register every TenPay V2 partner in application startup (Global.asax / Program.Main) before serving requests.
- Normalize and validate partner keys (trim, exact case) at registration and lookup time.
- Keep partner credentials in configuration and register them all in one bootstrap path.
- Add a startup smoke test that indexes each expected partner id to fail fast on missing registration.
- In multi-tenant systems, verify tenant-to-partner mapping before pay operations.
When it happens
Trigger: Accessing tenPayInfoCollection["somePartnerId"] where "somePartnerId" was never registered via TenPayInfoCollection.Register(...) (or the Register call ran in a different app domain / before this lookup).
Common situations: TenPay V2 partner credentials never registered at application startup; key typo or case mismatch between registration and lookup; config loaded in a different process/app pool than the one serving the pay request; multi-tenant code indexing by a partner id that has no V2 entry.
Related errors
- TenPayV3InfoCollection尚未注册Mch:
- 未获取到用于安全探测的微信支付公钥或平台证书。
- 没有设置证书加密类型(EncryptionType)
- Section is not found.
- AppId 不能为空。
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/8a757428fef10ecc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V2/TenPayInfoCollection.cs:81
//添加到全局变量
if (!name.IsNullOrEmpty())
{
Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_PartnerId = weixinPayInfo.PartnerId;
Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_Key = weixinPayInfo.Key;
Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_AppId = weixinPayInfo.AppId;
Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_AppKey = weixinPayInfo.AppKey;
Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_TenpayNotify = weixinPayInfo.TenPayNotify;
}
}
public new TenPayInfo this[string key]
{
get
{
if (!base.ContainsKey(key))
{
throw new WeixinException(string.Format("WeixinPayInfoCollection尚未注册Partner:{0}", key));
}
else
{
return base[key];
}
}
set
{
base[key] = value;
}
}
public TenPayInfoCollection()
: base(StringComparer.OrdinalIgnoreCase)
{
}
}View on GitHub (pinned to be573f6f94)