JeffreySu/WeiXinMPSDK · error · UnknownRequestMsgTypeException

未知的Event下属请求信息

Error message

未知的Event下属请求信息

What it means

The synchronous OnEventRequest dispatches Event-typed push messages to OnEvent_* handlers via a switch. If the event value has no case (an event type unknown to this SDK version), it throws UnknownRequestMsgTypeException('未知的Event下属请求信息'), surfacing unhandled WeChat events instead of silently ignoring them.

Solutions

  1. Upgrade Senparc.Weixin.MP / Senparc.Weixin to the latest release so the switch covers new event types.
  2. Override OnEventRequest in your MessageHandler and wrap base.OnEventRequest in try-catch for UnknownRequestMsgTypeException, returning an empty/success response so WeChat doesn't retry indefinitely.
  3. Inspect and log requestMessage.Event to identify which event is unmapped and add a custom handler for it.
  4. Disable the unsupported event push in the WeChat console until the SDK is upgraded.

Example fix

// before
public override IResponseMessageBase OnEventRequest(RequestMessageEvent requestMessage)
{
    return base.OnEventRequest(requestMessage); // throws on unknown event
}
// after
public override IResponseMessageBase OnEventRequest(RequestMessageEvent requestMessage)
{
    try
    {
        return base.OnEventRequest(requestMessage);
    }
    catch (UnknownRequestMsgTypeException)
    {
        Log.Warn($"Unhandled event: {requestMessage.Event}");
        return CreateResponseMessage<ResponseMessageNoResponse>();
    }
}
Defensive patterns

Strategy: try-catch

Type guard

bool isSupportedEvent = Enum.IsDefined(typeof(Event), requestMessage.Event);

Try / catch

try
{
    response = handler.OnEventRequest(eventMessage);
}
catch (UnknownRequestMsgTypeException ex)
{
    log.Warn($"Unknown WeChat event: {ex.Message}");
    response = handler.CreateResponseMessage<ResponseMessageNoResponse>();
}

Prevention

When it happens

Trigger: WeChat pushes an event whose value lacks a case in this SDK version's switch — e.g. newly introduced WeChat events, console-enabled beta features, or an old Senparc.Weixin.MP package behind the WeChat API. Triggered by any incoming event message routed through MessageHandler.Execute/OnEventRequest.

Common situations: Running an outdated NuGet package while WeChat added new events; enabling new event pushes (card, invoice, channel, etc.) in the WeChat MP console before upgrading the SDK; test accounts issuing newer events.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.MP/Senparc.Weixin.MP/MessageHandlers/MessageHandler.Event.cs:263

                //case Event.weapp_audit_success://
                //    responseMessage = OnEvent_WeAppAuditSuccessRequest(RequestMessage as RequestMessageEvent_WeAppAuditSuccess);
                //    break;
                //case Event.weapp_audit_fail://
                //    responseMessage = OnEvent_WeAppAuditFailRequest(RequestMessage as RequestMessageEvent_WeAppAuditFail);
                //    break;
                #endregion

                #region 微信电子发票
                case Event.user_authorize_invoice:
                    responseMessage = OnEvent_User_Authorize_Invoice(RequestMessage as RequestMessageEvent_User_Authorize_Invoice);
                    break;
                case Event.submit_invoice_title:
                    responseMessage = OnEvent_Submit_Invoice_Title(RequestMessage as RequestMessageEvent_Submit_Invoice_Title);
                    break;
                #endregion

                default:
                    throw new Exceptions.UnknownRequestMsgTypeException("未知的Event下属请求信息", null);
            }
            return responseMessage;
        }

        #region Event下属分类,接收事件方法

        /// <summary>
        /// Event事件类型请求之用户资料变更
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public virtual IResponseMessageBase OnEvent_UserInfoModifiedRequest(RequestMessageEvent_UserInfoModified requestMessage)
        {
            return DefaultResponseMessage(requestMessage);
        }
        /// <summary>
        /// Event事件类型请求之用户撤回
        /// </summary>

View on GitHub (pinned to be573f6f94)