{"record":{"id":"809a102d2e6ba47d","repo":"JeffreySu/WeiXinMPSDK","slug":"appid-componentcontainer-register","errorCode":null,"errorMessage":"此appId尚未注册，ComponentContainer.Register完成注册（全局执行一次即可）！","messagePattern":"此appId尚未注册，ComponentContainer\\.Register完成注册（全局执行一次即可）！","errorType":"exception","errorClass":"WeixinOpenException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Open/Senparc.Weixin.Open/Containers/ComponentContainer.cs","lineNumber":261,"sourceCode":"            if (!CheckRegistered(componentAppId) || getNewToken)\n            {\n                Register(componentAppId, componentAppSecret, null, null, null, name);\n            }\n        }\n\n        #region component_verify_ticket\n\n        /// <summary>\n        /// 获取ComponentVerifyTicket\n        /// </summary>\n        /// <param name=\"componentAppId\"></param>\n        /// <param name=\"getNewToken\"></param>\n        /// <returns>如果不存在，则返回null</returns>\n        public static string TryGetComponentVerifyTicket(string componentAppId, bool getNewToken = false)\n        {\n            if (!CheckRegistered(componentAppId))\n            {\n                throw new WeixinOpenException(UN_REGISTER_ALERT);\n            }\n\n            var bag = TryGetItem(componentAppId);\n            using (Cache.BeginCacheLock(LockResourceName + \".TryGetComponentVerifyTicket\", componentAppId))\n            {\n                bag = TryGetItem(componentAppId);//获锁后重新读取并二次检查过期状态\n                var componentVerifyTicket = bag.ComponentVerifyTicket;\n                if (getNewToken || componentVerifyTicket == default(string) || bag.ComponentVerifyTicketExpireTime < SystemTime.Now)\n                {\n                    if (GetComponentVerifyTicketFunc == null)\n                    {\n                        throw new WeixinOpenException(\"GetComponentVerifyTicketFunc必须在注册时提供！\", bag);\n                    }\n                    componentVerifyTicket = GetComponentVerifyTicketFunc(componentAppId).ConfigureAwait(false).GetAwaiter().GetResult(); //获取最新的componentVerifyTicket\n                    bag.ComponentVerifyTicket = componentVerifyTicket;\n                    bag.ComponentVerifyTicketExpireTime = ApiUtility.GetExpireTime(COMPONENT_VERIFY_TICKET_UPDATE_MINUTES * 60);\n                    Update(bag, null);//更新到缓存\n                }","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Containers/ComponentContainer.cs#L243-L279","documentation":"TryGetComponentVerifyTicket looks up the component_verify_ticket for a registered open-platform component. If CheckRegistered fails for the componentAppId it throws WeixinOpenException with the UN_REGISTER_ALERT message, meaning ComponentContainer.Register was never called (or app cache was flushed without re-registration).","triggerScenarios":"Calling ComponentContainer.TryGetComponentVerifyTicket, GetComponentAccessTokenResult, or componentVerifyTicket with an appId not registered via ComponentContainer.Register in the current process/cache.","commonSituations":"Forgot the one-time global registration at startup; app domain recycled and registration happens only in Application_Start of a worker that wasn't restarted; cache backend cleared; wrong componentAppId passed.","solutions":["Call ComponentContainer.Register(componentAppId, componentSecret, GetComponentVerifyTicketFunc) once at application startup.","Ensure registration runs in every process/app-domain (e.g. also in background workers), not just in the web root.","Confirm the componentAppId matches the registered one.","Check the cache is persistent/consistent so registration state survives restarts."],"exampleFix":"// before\nvar ticket = ComponentContainer.TryGetComponentVerifyTicket(componentAppId);\n// after\nComponentContainer.Register(componentAppId, componentSecret, GetComponentVerifyTicketFunc);\nvar ticket = ComponentContainer.TryGetComponentVerifyTicket(componentAppId);","handlingStrategy":"validation","validationCode":"if (!ComponentContainer.CheckRegistered(componentAppId))\n    ComponentContainer.Register(componentAppId, componentSecret, GetComponentVerifyTicketFunc);","typeGuard":null,"tryCatchPattern":"try { ticket = ComponentContainer.TryGetComponentVerifyTicket(componentAppId); }\ncatch (WeixinOpenException ex) { logger.Error(ex, \"Component not registered: {0}\", componentAppId); throw; }","preventionTips":["Register once globally at startup in every process","Use shared cache across instances","Validate appId configuration values"],"tags":["weixin-open","container","registration","unregistered-appid"],"backgroundTag":"resource-not-found","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"}