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
- Upgrade Senparc.Weixin / Senparc.Weixin.MP to the latest version so new event types are mapped.
- Override OnEventRequestAsync (or the DefaultAsyncMessageHandler) in your MessageHandler subclass to catch UnknownRequestMsgTypeException and return a success/empty response to WeChat.
- Log the raw request XML (RequestMessage.Event) to identify the unknown event and handle it in an override.
- 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
- Keep Senparc.Weixin.MP packages updated to track new WeChat event types.
- Override OnEventRequestAsync with a default fallback instead of relying on base throwing.
- Log raw callback XML so unknown events can be identified and added later.
- Only enable event push features in the WeChat console that your SDK version supports.
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
- 未知的Event下属请求信息
- DefaultMessageHandlerAsyncEvent 类型未作处理:
- 此appId尚未注册,请先使用WxCardApiTicketContainer.Register完成注册(全局执行一次即…
- 注册委托容量必须大于 0。
- 当前已有 个注册委托,不能把容量降低到 。
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)