JeffreySu/WeiXinMPSDK · error · UnknownRequestMsgTypeException

InfoType: 在RequestMessageFactory中没有对应的处理程序!

Error message

InfoType:{0} 在RequestMessageFactory中没有对应的处理程序!

What it means

RequestMessageFactory.GetRequestEntity maps the push XML's InfoType to a concrete request message class; the default switch branch throws UnknownRequestMsgTypeException when the InfoType has no mapped class in this library version. The comment notes the factory is intentionally strict so callers can catch this for forward-compatibility.

Solutions

  1. Upgrade Senparc.Weixin.Open to the latest NuGet version to pick up new InfoType mappings.
  2. Catch UnknownRequestMsgTypeException (or WeixinException) when calling GetRequestEntity and handle/log unknown pushes gracefully.
  3. Report or check the InfoType in the raw XML; if it is custom, route it to your own parser before the factory.

Example fix

// before
var requestMessage = RequestMessageFactory.GetRequestEntity(doc);
// after
try { var requestMessage = RequestMessageFactory.GetRequestEntity(doc); }
catch (UnknownRequestMsgTypeException ex)
{
    logger.LogWarning("Unknown InfoType push: {Info}", ex.Message);
    return; // ack WeChat
}
Defensive patterns

Strategy: try-catch

Validate before calling

var infoType = doc.Root?.Element("InfoType")?.Value;
if (string.IsNullOrEmpty(infoType))
    throw new InvalidOperationException("Push XML missing InfoType");

Type guard

bool IsKnownInfoType(string t) => Enum.IsDefined(typeof(RequestInfoType), t);

Try / catch

try { var msg = RequestMessageFactory.GetRequestEntity(doc); }
catch (UnknownRequestMsgTypeException ex)
{ logger.LogWarning(ex.Message); return Content("success"); }

Prevention

When it happens

Trigger: WeChat pushes a third-party-platform event whose InfoType is not in the RequestInfoType enum/mapping of the installed Senparc.Weixin.Open version (e.g. a brand-new notify type), while parsing the component callback XML.

Common situations: Running an outdated SDK against a WeChat platform that added new event types; test/dev callbacks with fabricated InfoType values; probing pushes from WeChat QA environments.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.Open/Senparc.Weixin.Open/RequestMessageFactory.cs:120

                            requestMessage = new RequestMessageIcpFilingVerify();
                        break;
                    case RequestInfoType.notify_apply_icpfiling_result:
                            requestMessage = new RequestMessageIcpFilingApply();
                        break;
                    case RequestInfoType.notify_3rd_wxa_auth:
                        requestMessage = new RequestMessage3rdWxaAuth();
                        break;
                    case RequestInfoType.notify_3rd_wxa_wxverify:
                        requestMessage = new RequestMessage3rdWxaWxVerify();
                        break;
                    case RequestInfoType.order_path_apply_result_notify:
                        requestMessage = new RequestMessageOrderPathApplyResultNotify();
                        break;
                    case RequestInfoType.order_path_audit_result_notify:
                        requestMessage = new RequestMessageOrderPathAuditResultNotify();
                        break;
                    default:
                        throw new UnknownRequestMsgTypeException(string.Format("InfoType:{0} 在RequestMessageFactory中没有对应的处理程序!", infoType), new ArgumentOutOfRangeException());//为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常
                }
                EntityHelper.FillEntityWithXml(requestMessage, doc);
            }
            catch (ArgumentException ex)
            {
                throw new WeixinException(string.Format("RequestMessage转换出错!可能是InfoType不存在!,XML:{0}", doc.ToString()), ex);
            }
            return requestMessage;
        }


        /// <summary>
        /// 获取XDocument转换后的IRequestMessageBase实例。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IRequestMessageBase GetRequestEntity(string xml)
        {

View on GitHub (pinned to be573f6f94)