{"record":{"id":"f74ec895feb01b45","repo":"JeffreySu/WeiXinMPSDK","slug":"tenpayv3infocollection-mch-0","errorCode":null,"errorMessage":"TenPayV3InfoCollection尚未注册Mch：{0}","messagePattern":"TenPayV3InfoCollection尚未注册Mch：(.+?)","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/TenPayV3InfoCollection.cs","lineNumber":105,"sourceCode":"                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].TenPayV3_WxOpenTenpayNotify = tenPayV3Info.TenPayV3_WxOpenNotify;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].TenPayV3_SubMchId = tenPayV3Info.Sub_MchId;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].TenPayV3_SubAppId = tenPayV3Info.Sub_AppId;\n                Senparc.Weixin.Config.SenparcWeixinSetting.Items[name].TenPayV3_SubAppSecret = tenPayV3Info.Sub_AppSecret;\n            }\n        }\n\n        /// <summary>\n        /// 索引 TenPayV3Info\n        /// </summary>\n        /// <param name=\"key\"></param>\n        /// <returns></returns>\n        public new TenPayV3Info this[string key]\n        {\n            get\n            {\n                if (!base.ContainsKey(key))\n                {\n                    throw new WeixinException(string.Format(\"TenPayV3InfoCollection尚未注册Mch：{0}\", key));\n                }\n                else\n                {\n                    return base[key];\n                }\n            }\n            set\n            {\n                base[key] = value;\n            }\n        }\n\n        /// <summary>\n        /// TenPayV3InfoCollection 构造函数\n        /// </summary>\n        public TenPayV3InfoCollection() : base(StringComparer.OrdinalIgnoreCase)\n        {\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/TenPayV3InfoCollection.cs#L87-L123","documentation":"TenPayV3InfoCollection throws this WeixinException from its string indexer when the requested merchant (Mch) key is not present among the registered TenPayV3Info entries. Like the V2 collection, lookups must be preceded by Register; the indexer throws instead of returning null.","triggerScenarios":"Accessing tenPayV3InfoCollection[\"someMchId\"] where no TenPayV3Info with that MchId was registered via TenPayV3InfoCollection.Register(...) in the current application instance.","commonSituations":"TenPay V3 merchant credentials not registered at startup; MchId typo, trailing space, or case mismatch; configuration registered in a different environment (dev vs prod app pool); multi-tenant systems indexing by a merchant id that was never added.","solutions":["Register the merchant before use: TenPayV3InfoCollection.Register(new TenPayV3Info(appId, appSecret, mchId, key, certPath, certPassword, notifyUrl)) at application startup.","Verify the indexer key exactly matches the registered MchId.","Guard with a ContainsKey check (or wrap the lookup) before indexing in multi-tenant flows.","Log the set of registered Mch keys at startup and compare with the failing key."],"exampleFix":"// before\nvar v3Info = TenPayV3InfoCollection.Data[mchId]; // throws if unregistered\n// after\nif (TenPayV3InfoCollection.Data.ContainsKey(mchId))\n{\n    var v3Info = TenPayV3InfoCollection.Data[mchId];\n}\nelse\n{\n    TenPayV3InfoCollection.Register(new TenPayV3Info(appId, appSecret, mchId, key, certPath, certPassword, notifyUrl));\n}","handlingStrategy":"try-catch","validationCode":"bool mchRegistered = TenPayV3InfoCollection.Data.ContainsKey(mchId);\nif (!mchRegistered) throw new InvalidOperationException($\"Mch '{mchId}' is not registered. Call TenPayV3InfoCollection.Register at startup.\");","typeGuard":"bool TryGetTenPayV3Info(string mchId, out TenPayV3Info info)\n{\n    if (TenPayV3InfoCollection.Data.ContainsKey(mchId)) { info = TenPayV3InfoCollection.Data[mchId]; return true; }\n    info = null; return false;\n}","tryCatchPattern":"try { var info = TenPayV3InfoCollection.Data[mchId]; }\ncatch (WeixinException ex) when (ex.Message.StartsWith(\"TenPayV3InfoCollection尚未注册Mch\"))\n{\n    log.Error(ex.Message);\n    throw new InvalidOperationException(\"Register the TenPay V3 merchant at application startup.\", ex);\n}","preventionTips":["Register all TenPay V3 merchants (appId, mchId, key, cert) during application startup.","Trim and case-check MchId values when reading from configuration.","Log registered Mch ids at startup to diagnose environment mismatches quickly.","Use a ContainsKey guard before indexed access in multi-tenant payment flows.","Add an integration test that resolves every configured merchant from the collection before deployment."],"tags":["wechat-pay","tenpay-v3","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"}