JeffreySu/WeiXinMPSDK · error · UnknownRequestMsgTypeException

未知的Event下属请求信息

Error message

未知的Event下属请求信息

What it means

OnEventRequestAsync dispatches push events (Event enum) to typed OnEvent_* handlers. When the event's MsgType is Event but the specific event value has no matching case in the switch, the library throws UnknownRequestMsgTypeException('未知的Event下属请求信息'). This guards against unhandled/new WeChat event types rather than silently dropping them.

Solutions

  1. Upgrade Senparc.Weixin / Senparc.Weixin.MP to the latest version so new event types are mapped.
  2. Override OnEventRequestAsync (or the DefaultAsyncMessageHandler) in your MessageHandler subclass to catch UnknownRequestMsgTypeException and return a success/empty response to WeChat.
  3. Log the raw request XML (RequestMessage.Event) to identify the unknown event and handle it in an override.
  4. Avoid enabling unsupported event features in the WeChat console until the SDK supports them.

Example fix

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

Strategy: try-catch

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: WeChat server pushes an event that this version of Senparc.Weixin.MP does not map in its switch (new WeChat event types, beta events, or event values enabled on the WeChat MP console but unsupported by the installed SDK version); a custom/modified Event enum deserialization producing an unmapped value.

Common situations: Enabling new WeChat features (e.g. new invoice, card, or mini-program events) in the MP admin console while running an older SDK; WeChat adding an event type after the SDK release; forwarding messages from a test account issuing events the SDK predates.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.MP/Senparc.Weixin.MP/MessageHandlers/Async/MessageHandlerAsync.Event.cs:257

                case Event.giftcard_send_to_friend:
                    responseMessage = await OnEvent_GiftCard_Send_To_FriendRequestAsync(RequestMessage as RequestMessageEvent_GiftCard_Send_To_Friend).ConfigureAwait(false);
                    break;

                case Event.giftcard_user_accept:
                    responseMessage = await OnEvent_GiftCard_User_AcceptRequestAsync(RequestMessage as RequestMessageEvent_GiftCard_User_Accept).ConfigureAwait(false);
                    break;

                #endregion

                #region 微信电子发票
                case Event.user_authorize_invoice:
                    responseMessage = await OnEvent_User_Authorize_InvoiceAsync(RequestMessage as RequestMessageEvent_User_Authorize_Invoice).ConfigureAwait(false);
                    break;
                #endregion

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

            string d = null;
            string s = null;
            string n = s ?? d ?? "1";

            return responseMessage;
        }

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

        /// <summary>
        /// 【异步方法】Event事件类型请求之用户资料变更
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public virtual async Task<IResponseMessageBase> OnEvent_UserInfoModifiedRequesAsync(RequestMessageEvent_UserInfoModified requestMessage)
        {

View on GitHub (pinned to be573f6f94)