JeffreySu/WeiXinMPSDK · error · UnknownRequestMsgTypeException
InfoType: 在RequestMessageFactory中没有对应的处理程序!
Error message
InfoType:{0} 在RequestMessageFactory中没有对应的处理程序! What it means
RequestMessageFactory.GetRequestEntity received an InfoType (event-driven, e.g. contact/party change callbacks) that has no handler branch in its switch, and threw UnknownRequestMsgTypeException (derived with an ArgumentOutOfRangeException). The comment notes this is done to maximize tolerance for new WeChat types — callers are advised to catch this exception.
Solutions
- Catch UnknownRequestMsgTypeException around message parsing and reply 'success' to acknowledge unknown events.
- Upgrade Senparc.Weixin.Work so the new InfoType is handled.
- Log the InfoType from the exception message and, if needed, handle it manually by parsing the XML yourself.
- Report/patch the missing InfoType in the factory switch.
Example fix
// before
var msg = RequestMessageFactory.GetRequestEntity(...); // throws on new InfoType
// after
try
{
var msg = RequestMessageFactory.GetRequestEntity(...);
}
catch (UnknownRequestMsgTypeException ex)
{
Logger.Warn(ex.Message);
return "success"; // ack unknown event types
} Defensive patterns
Strategy: try-catch
Validate before calling
var infoType = doc.SelectSingleNode("//InfoType")?.InnerText;
var supported = new[] { "subscribe", "unsubscribe", "change_contact", "change_external_contact" /* etc per SDK */ };
if (infoType != null && !supported.Contains(infoType))
{
Logger.Info("Unrecognized InfoType, acking: " + infoType);
return "success";
} Try / catch
try
{
var msg = RequestMessageFactory.GetRequestEntity(...);
}
catch (UnknownRequestMsgTypeException ex)
{
Logger.Warn(ex.Message);
return "success"; // per SDK guidance, catch this for forward-compat
} Prevention
- Catch UnknownRequestMsgTypeException at the callback boundary — the SDK docs explicitly recommend it for forward compatibility.
- Upgrade the SDK when WeChat Work introduces new event types.
- Log unknown InfoTypes to track new WeChat features.
When it happens
Trigger: A Work callback push arrives with <InfoType> set to a value the installed SDK version doesn't implement (the switch's default branch), e.g. newly added WeChat Work event types.
Common situations: New WeChat Work server event pushed before SDK support; running an old Senparc.Weixin.Work version while WeChat enables new callback types on your account.
Related errors
- RequestMessage转换出错!可能是MsgType不存在!,XML:
- RequestMessage转换异常!InfoType类型存在的情况下无法处理!,XML:
- RequestMessage转换出错!MsgType和InfoType都不存在!,XML:
- InfoType: 在RequestMessageFactory中没有对应的处理程序!
- RequestMessage转换出错!可能是InfoType不存在!,XML:
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/ac226762e761ecae.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/RequestMessageFactory.cs:192
case "MSGAUDIT_NOTIFY":
requestMessage = new RequestMessageEvent_MsgAuditNotify();
break;
case "CREATE":
requestMessage = new RequestMessageEvent_Change_ExternalContact_Create();
break;
case "UPDATE":
requestMessage = new RequestMessageEvent_Change_ExternalContact_Update();
break;
case "DISMISS":
requestMessage = new RequestMessageEvent_Change_ExternalContact_Dismiss();
break;
default:
requestMessage = new RequestMessageEvent_Change_ExternalContact_Base();
break;
}
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);
}
}
else
{
throw new WeixinException(string.Format("RequestMessage转换出错!MsgType和InfoType都不存在!,XML:{0}", doc.ToString()));
}
return requestMessage;
}
/// <summary>View on GitHub (pinned to be573f6f94)