{"record":{"id":"8a757428fef10ecc","repo":"JeffreySu/WeiXinMPSDK","slug":"weixinpayinfocollection-partner-0","errorCode":null,"errorMessage":"WeixinPayInfoCollection尚未注册Partner：{0}","messagePattern":"WeixinPayInfoCollection尚未注册Partner：(.+?)","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V2/TenPayInfoCollection.cs","lineNumber":81,"sourceCode":"\n            //添加到全局变量\n            if (!name.IsNullOrEmpty())\n            {\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_PartnerId = weixinPayInfo.PartnerId;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_Key = weixinPayInfo.Key;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_AppId = weixinPayInfo.AppId;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_AppKey = weixinPayInfo.AppKey;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].WeixinPay_TenpayNotify = weixinPayInfo.TenPayNotify;\n            }\n        }\n\n        public new TenPayInfo this[string key]\n        {\n            get\n            {\n                if (!base.ContainsKey(key))\n                {\n                    throw new WeixinException(string.Format(\"WeixinPayInfoCollection尚未注册Partner：{0}\", key));\n                }\n                else\n                {\n                    return base[key];\n                }\n            }\n            set\n            {\n                base[key] = value;\n            }\n        }\n\n        public TenPayInfoCollection()\n            : base(StringComparer.OrdinalIgnoreCase)\n        {\n\n        }\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V2/TenPayInfoCollection.cs#L63-L99","documentation":"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.","triggerScenarios":"Accessing tenPayInfoCollection[\"somePartnerId\"] where \"somePartnerId\" was never registered via TenPayInfoCollection.Register(...) (or the Register call ran in a different app domain / before this lookup).","commonSituations":"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.","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)."],"exampleFix":"// before\nvar tenPayInfo = TenPayInfoCollection.Data[partnerId]; // throws if unregistered\n// after\nif (TenPayInfoCollection.Data.ContainsKey(partnerId))\n{\n    var tenPayInfo = TenPayInfoCollection.Data[partnerId];\n}\nelse\n{\n    TenPayInfoCollection.Register(new TenPayInfo(partnerId, appId, appSecret, tenPayPartnerKey, tenPayNotifyUrl));\n}","handlingStrategy":"try-catch","validationCode":"bool partnerRegistered = TenPayInfoCollection.Data.ContainsKey(partnerId);\nif (!partnerRegistered) throw new InvalidOperationException($\"Partner '{partnerId}' is not registered. Call TenPayInfoCollection.Register at startup.\");","typeGuard":"bool TryGetTenPayInfo(string partnerId, out TenPayInfo info)\n{\n    if (TenPayInfoCollection.Data.ContainsKey(partnerId)) { info = TenPayInfoCollection.Data[partnerId]; return true; }\n    info = null; return false;\n}","tryCatchPattern":"try { var info = TenPayInfoCollection.Data[partnerId]; }\ncatch (WeixinException ex) when (ex.Message.StartsWith(\"WeixinPayInfoCollection尚未注册Partner\"))\n{\n    log.Error(ex.Message);\n    throw new InvalidOperationException(\"Register the TenPay V2 partner at application startup.\", ex);\n}","preventionTips":["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."],"tags":["wechat-pay","tenpay","configuration","unregistered-key"],"backgroundTag":"missing-config-key","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}