JeffreySu/WeiXinMPSDK · error · WeixinException

RequestMessage转换异常!InfoType类型存在的情况下无法处理!,XML:

Error message

RequestMessage转换异常!InfoType类型存在的情况下无法处理!,XML:{0}

What it means

RequestMessageFactory.GetRequestEntity recognized the InfoType (the switch matched and built a requestMessage), but EntityHelper.FillEntityWithXml threw ArgumentException while mapping XML fields onto the entity. The factory wraps this in a WeixinException stating the InfoType exists but could not be processed, including the raw XML.

Solutions

  1. Read the XML in the WeixinException message and compare against the expected entity fields for that InfoType.
  2. Upgrade Senparc.Weixin.Work to a version matching the current event payload schema.
  3. Catch WeixinException in the callback controller, log the XML, and return 'success' to prevent WeChat retries.
  4. If you construct test XML, make it match the documented entity structure exactly.

Example fix

// before
var msg = RequestMessageFactory.GetRequestEntity(...); // WeixinException on fill failure
// after
try
{
    var msg = RequestMessageFactory.GetRequestEntity(...);
}
catch (WeixinException ex)
{
    Logger.Error("Work callback fill failed: " + ex.Message);
    return "success";
}
Defensive patterns

Strategy: try-catch

Validate before calling

var infoType = doc.SelectSingleNode("//InfoType")?.InnerText;
if (string.IsNullOrEmpty(infoType) || doc.DocumentElement == null || doc.DocumentElement.ChildNodes.Count == 0)
{
    Logger.Warn("Callback XML missing expected fields: " + rawXml);
    return "success";
}

Try / catch

try
{
    var msg = RequestMessageFactory.GetRequestEntity(...);
}
catch (WeixinException ex)
{
    Logger.Error("Entity fill failed: " + ex.Message); // includes raw XML
    return "success";
}

Prevention

When it happens

Trigger: A Work callback whose InfoType is known but whose XML body doesn't match the entity's expected fields — e.g. changed/extended event payloads, or XML missing required nodes the entity deserializer expects, causing FillEntityWithXml to throw ArgumentException.

Common situations: WeChat altering event payload structure between SDK versions; custom XML in unit tests that lacks expected fields; mismatched SDK entity definitions for an InfoType.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/RequestMessageFactory.cs:198

                                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>
        /// 获取XDocument转换后的IRequestMessageBase实例。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IWorkRequestMessageBase GetRequestEntity<TMC>(TMC messageContext, string xml)
            where TMC : class, IMessageContext<IWorkRequestMessageBase, IWorkResponseMessageBase>, new()

View on GitHub (pinned to be573f6f94)