{"record":{"id":"1ac9044f319098f7","repo":"JeffreySu/WeiXinMPSDK","slug":"requestmessage-infotype-xml-0-requestmessagefactory","errorCode":null,"errorMessage":"RequestMessage转换异常！InfoType类型存在的情况下无法处理！，XML：{0}","messagePattern":"RequestMessage转换异常！InfoType类型存在的情况下无法处理！，XML：(.+?)","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/RequestMessageFactory.cs","lineNumber":198,"sourceCode":"                                case \"UPDATE\":\n                                    requestMessage = new RequestMessageEvent_Change_ExternalContact_Update();\n                                    break;\n                                case \"DISMISS\":\n                                    requestMessage = new RequestMessageEvent_Change_ExternalContact_Dismiss();\n                                    break;\n                                default:\n                                    requestMessage = new RequestMessageEvent_Change_ExternalContact_Base();\n                                    break;\n                            }\n                            break;\n                        default:\n                            throw new UnknownRequestMsgTypeException(string.Format(\"InfoType：{0} 在RequestMessageFactory中没有对应的处理程序！\", infoType), new ArgumentOutOfRangeException());//为了能够对类型变动最大程度容错（如微信目前还可以对公众账号suscribe等未知类型，但API没有开放），建议在使用的时候catch这个异常\n                    }\n                    EntityHelper.FillEntityWithXml(requestMessage, doc);\n                }\n                catch (ArgumentException ex)\n                {\n                    throw new WeixinException(string.Format(\"RequestMessage转换异常！InfoType类型存在的情况下无法处理！，XML：{0}\", doc.ToString()), ex);\n                }\n            }\n            else\n            {\n                throw new WeixinException(string.Format(\"RequestMessage转换出错！MsgType和InfoType都不存在！，XML：{0}\", doc.ToString()));\n            }\n\n            return requestMessage;\n        }\n\n\n        /// <summary>\n        /// 获取XDocument转换后的IRequestMessageBase实例。\n        /// 如果MsgType不存在，抛出UnknownRequestMsgTypeException异常\n        /// </summary>\n        /// <returns></returns>\n        public static IWorkRequestMessageBase GetRequestEntity<TMC>(TMC messageContext, string xml)\n            where TMC : class, IMessageContext<IWorkRequestMessageBase, IWorkResponseMessageBase>, new()","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/RequestMessageFactory.cs#L180-L216","documentation":"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.","triggerScenarios":"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.","commonSituations":"WeChat altering event payload structure between SDK versions; custom XML in unit tests that lacks expected fields; mismatched SDK entity definitions for an InfoType.","solutions":["Read the XML in the WeixinException message and compare against the expected entity fields for that InfoType.","Upgrade Senparc.Weixin.Work to a version matching the current event payload schema.","Catch WeixinException in the callback controller, log the XML, and return 'success' to prevent WeChat retries.","If you construct test XML, make it match the documented entity structure exactly."],"exampleFix":"// before\nvar msg = RequestMessageFactory.GetRequestEntity(...); // WeixinException on fill failure\n// after\ntry\n{\n    var msg = RequestMessageFactory.GetRequestEntity(...);\n}\ncatch (WeixinException ex)\n{\n    Logger.Error(\"Work callback fill failed: \" + ex.Message);\n    return \"success\";\n}","handlingStrategy":"try-catch","validationCode":"var infoType = doc.SelectSingleNode(\"//InfoType\")?.InnerText;\nif (string.IsNullOrEmpty(infoType) || doc.DocumentElement == null || doc.DocumentElement.ChildNodes.Count == 0)\n{\n    Logger.Warn(\"Callback XML missing expected fields: \" + rawXml);\n    return \"success\";\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var msg = RequestMessageFactory.GetRequestEntity(...);\n}\ncatch (WeixinException ex)\n{\n    Logger.Error(\"Entity fill failed: \" + ex.Message); // includes raw XML\n    return \"success\";\n}","preventionTips":["Match SDK version to the WeChat Work event payload schema you receive.","Validate test XML against the entity definitions before running handler tests.","Persist the raw XML from the exception message when filing SDK bugs."],"tags":["weixin-work","xml-parsing","entity-binding","message-factory"],"backgroundTag":"schema-validation-failed","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}