JeffreySu/WeiXinMPSDK · error · UnknownRequestMsgTypeException

未知的Event下属请求信息

Error message

未知的Event下属请求信息

What it means

This is the top-level default case of OnEventRequestAsync: when the Event value of a callback matches no handled event case (including all sub-dispatchers like change_contact, change_external_contact, living status, approval, vip account approval, etc.), the handler throws UnknownRequestMsgTypeException. It means the library received a WeCom event type it cannot model.

Solutions

  1. Upgrade Senparc.Weixin.Work to the latest version to gain dispatch cases for new WeCom events
  2. Derive WorkMessageHandler and override OnEventRequestAsync, adding a case (or a permissive default) for the unknown event
  3. Catch UnknownRequestMsgTypeException in the callback controller, log the raw Event value, and return 'success' so WeCom stops retrying
  4. Verify Token/EncodingAESKey correctness if the Event value looks corrupted rather than genuinely new

Example fix

// before
public async Task<ActionResult> Callback(PostModel postModel) { var r = await messageHandler.BuildResponseMessageAsync(); ... }
// after
try { var r = await messageHandler.BuildResponseMessageAsync(); ... }
catch (UnknownRequestMsgTypeException ex) { _logger.LogWarning(ex, "Unhandled Event: {Event}", postModel.Event); return Content("success"); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (!Enum.IsDefined(typeof(Event), eventMessage.Event)) { return null; }

Type guard

bool IsKnownWeComEvent(IRequestMessageEventBase e) => Enum.IsDefined(typeof(Event), e.Event);

Try / catch

try { response = await handler.BuildResponseMessageAsync(); } catch (UnknownRequestMsgTypeException ex) { _logger.LogWarning(ex, "Unhandled Event: {Event}", evt?.Event); return Content("success"); }

Prevention

When it happens

Trigger: A WeCom callback with an Event value not present in the handler's switch — typically a newly released WeCom event (or an event from a feature the app didn't enable when the library was written) reaches OnEventRequestAsync.

Common situations: WeCom platform adding new callback events after your library release; events from other WeCom apps/features hitting the same callback URL; decrypted Event value altered by a wrong Token/EncodingAESKey causing a mismatch.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/be77bdf0aaa2339d. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs:546

                            RequestMessage as RequestMessageEvent_Delete_Schedule);
                    break;
                case Event.respond_schedule: // 日程回执事件
                    responseMessage = await
                        OnEvent_RespondScheduleRequestAsync(
                            RequestMessage as RequestMessageEvent_Respond_Schedule);
                    break;
                case Event.submit_vip_account_approval: // 成员提交高级功能账号申请
                    responseMessage = await
                        OnEvent_SubmitVipAccountApprovalRequestAsync(
                            RequestMessage as RequestMessageEvent_Submit_Vip_Account_Approval);
                    break;
                case Event.finish_vip_account_approval: // 成员高级功能账号申请终止
                    responseMessage = await
                        OnEvent_FinishVipAccountApprovalRequestAsync(
                            RequestMessage as RequestMessageEvent_Finish_Vip_Account_Approval);
                    break;
                default:
                    throw new UnknownRequestMsgTypeException("未知的Event下属请求信息", null);
            }

            return responseMessage;
        }

        #region Event 下属分类

        /// <summary>
        /// Event事件类型请求之CLICK
        /// </summary>
        public virtual async Task<IWorkResponseMessageBase> OnEvent_ClickRequestAsync(
            RequestMessageEvent_Click requestMessage)
        {
            return await Task.FromResult(OnEvent_ClickRequest(requestMessage)).ConfigureAwait(false);
        }

        /// <summary>
        /// 事件之URL跳转视图(View)

View on GitHub (pinned to be573f6f94)