{"record":{"id":"e3b6b862aa78da15","repo":"JeffreySu/WeiXinMPSDK","slug":"tenpayv3infocollection-mch-0-e3b6b8","errorCode":null,"errorMessage":"TenPayV3InfoCollection尚未注册Mch：{0}","messagePattern":"TenPayV3InfoCollection尚未注册Mch：(.+?)","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayV3InfoCollection.cs","lineNumber":136,"sourceCode":"            var tenpayV3InfoKey = TenPayHelper.GetRegisterKey(senparcWeixinSettingForTenpayV3.TenPayV3_MchId, senparcWeixinSettingForTenpayV3.TenPayV3_SubMchId);\n            var pubKey = await Data[tenpayV3InfoKey].GetPublicKeyAsync(tenpaySerialNumber, senparcWeixinSettingForTenpayV3, cancellationToken).ConfigureAwait(false);\n            return pubKey;\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                lock (_syncRoot)\n                {\n                    if (!base.TryGetValue(key, out var value))\n                    {\n                        throw new WeixinException(string.Format(\"TenPayV3InfoCollection尚未注册Mch：{0}\", key));\n                    }\n\n                    return value;\n                }\n            }\n            set\n            {\n                lock (_syncRoot)\n                {\n                    base[key] = value;\n                }\n            }\n        }\n\n        /// <summary>\n        /// 获取当前注册数量。\n        /// </summary>\n        public new int Count","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayV3InfoCollection.cs#L118-L154","documentation":"TenPayV3InfoCollection is a thread-safe registry of TenPayV3 merchant configs keyed by merchant (Mch) name. This WeixinException is thrown by the indexer getter when the requested Mch key has never been registered, so the library refuses to return an unknown/default merchant config.","triggerScenarios":"Calling the indexer (e.g. TenPayV3InfoCollection[mchName]) or any API that resolves config by Mch key before Register()/RegisterCollection() was called with that key, or with a misspelled key.","commonSituations":"Config load order bugs (using the collection in a startup path that runs before registration), typos or case mismatch in the Mch name, multiple TenPayV3 merchants configured but the wrong key passed, or app restarts wiping the in-memory collection.","solutions":["Register the merchant before use: TenPayV3InfoCollection.Register(new TenPayV3Info(...)) with the exact key you later look up","Log/print TenPayV3InfoCollection.GetCollection().Keys (or TryGetValue) to verify the key spelling and registration at startup","Move registration earlier in the app lifecycle (e.g. application start / DI singleton init) so it precedes all payment calls","If a default should always exist, register a default TenPayV3Info and look it up with a constant key"],"exampleFix":"// before\nvar info = TenPayV3InfoCollection[\"mch_1000\"];\n// after\nif (TenPayV3InfoCollection.TryGet(\"mch_1000\", out var info)) { /* use info */ }\nelse { TenPayV3InfoCollection.Register(new TenPayV3Info(appId, mchId, key, appSecret, certPath)); }","handlingStrategy":"validation","validationCode":"if (TenPayV3InfoCollection.TryGet(mchName, out var info)) { /* proceed */ } else { throw new InvalidOperationException($\"Mch '{mchName}' not registered\"); }","typeGuard":"static bool IsMchRegistered(string key) => TenPayV3InfoCollection.GetCollection() is { } c && c.ContainsKey(key);","tryCatchPattern":"try { var info = TenPayV3InfoCollection[mchName]; ... } catch (WeixinException ex) { log.Error(\"Mch config missing: {0}\", mchName); throw new ConfigMissingException(ex); }","preventionTips":["Register all merchants in a single startup method","Use constants for Mch keys instead of literals","Add a startup smoke test that resolves every configured Mch key"],"tags":["config","tenpay","key-not-found"],"backgroundTag":"missing-required-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"}