{"record":{"id":"00b3d33c3b155680","repo":"JeffreySu/WeiXinMPSDK","slug":"authorizercontainer-componentcontainer-componentappid-0","errorCode":null,"errorMessage":"注册AuthorizerContainer之前，必须先注册对应的ComponentContainer！ComponentAppId：{0},AuthorizerAppId:{1}","messagePattern":"注册AuthorizerContainer之前，必须先注册对应的ComponentContainer！ComponentAppId：(.+?),AuthorizerAppId:(.+?)","errorType":"exception","errorClass":"WeixinOpenException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Open/Senparc.Weixin.Open/Containers/AuthorizerContainer.cs","lineNumber":494,"sourceCode":"        #endregion\n\n        #endregion\n\n\n        #region 异步方法\n\n        /// <summary>\n        /// 【异步方法】注册应用凭证信息，此操作只是注册，不会马上获取Ticket，并将清空之前的Ticket，\n        /// </summary>\n        /// <param name=\"authorizerAppId\"></param>\n        /// <param name=\"componentAppId\"></param>\n        /// <param name=\"name\">标记Authorizer名称（如微信公众号名称），帮助管理员识别</param>\n        private static async Task RegisterAsync(string componentAppId, string authorizerAppId, string name = null)\n        {\n            var componentBag = await ComponentContainer.TryGetItemAsync(componentAppId);\n            if (componentBag == null)\n            {\n                throw new WeixinOpenException(string.Format(\"注册AuthorizerContainer之前，必须先注册对应的ComponentContainer！ComponentAppId：{0},AuthorizerAppId:{1}\", componentAppId, authorizerAppId));\n            }\n\n            SetRegistrationCallback(authorizerAppId, async () =>\n             {\n                 //using (FlushCache.CreateInstance())\n                 //{\n                 var bag = new AuthorizerBag()\n                 {\n                     Name = name,\n\n                     AuthorizerAppId = authorizerAppId,\n                     ComponentAppId = componentAppId,\n\n                     AuthorizationInfo = new AuthorizationInfo(),\n                     AuthorizationInfoExpireTime = DateTimeOffset.MinValue,\n\n                     AuthorizerInfo = new AuthorizerInfo(),\n                     //AuthorizerInfoExpireTime = DateTimeOffset.MinValue,","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Open/Senparc.Weixin.Open/Containers/AuthorizerContainer.cs#L476-L512","documentation":"AuthorizerContainer.RegisterAsync requires the parent open-platform ComponentContainer to already be registered for the given componentAppId. When ComponentContainer.TryGetItemAsync returns null, it throws WeixinOpenException telling you to register the ComponentContainer first.","triggerScenarios":"Calling AuthorizerContainer.Register (or TryRegisterAsync) with a componentAppId that was never registered via ComponentContainer.Register, or a componentAppId with a typo.","commonSituations":"Startup code registers authorizers before the component; different componentAppId strings between environments (dev/prod); app settings typo; DI container ordering runs authorizer registration before component registration.","solutions":["Call ComponentContainer.Register(componentAppId, componentSecret, ...) before AuthorizerContainer.Register.","Verify the componentAppId matches exactly (no whitespace/typo) the one used in ComponentContainer.Register.","Move component registration to the earliest point of application startup.","Guard with ComponentContainer.CheckRegistered(componentAppId) before authorizer registration."],"exampleFix":"// before\nawait AuthorizerContainer.RegisterAsync(componentAppId, authorizerAppId, name);\n// after\nComponentContainer.Register(componentAppId, componentSecret, componentName);\nawait AuthorizerContainer.RegisterAsync(componentAppId, authorizerAppId, name);","handlingStrategy":"validation","validationCode":"if (!ComponentContainer.CheckRegistered(componentAppId))\n    throw new InvalidOperationException($\"Register ComponentContainer for {componentAppId} first\");","typeGuard":null,"tryCatchPattern":"try { await AuthorizerContainer.RegisterAsync(componentAppId, authorizerAppId, name); }\ncatch (WeixinOpenException ex) { logger.Error(ex, \"Component not registered\"); throw; }","preventionTips":["Register ComponentContainer as the first startup step","Centralize appId configuration to avoid typos","Add an integration test that registers containers in order"],"tags":["weixin-open","container","registration","dependency-order"],"backgroundTag":"missing-required-config","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"}