JeffreySu/WeiXinMPSDK · error · WeixinException
ResponseMessageBase.CreateFromResponseXml
Error message
ResponseMessageBase.CreateFromResponseXml<T>过程发生异常!
What it means
CreateFromResponseXml<T> parses a response XML string into a strongly typed response entity (resolving T, filling via FillEntityWithXml). Any failure — malformed XML, XML not matching the entity schema, or T not being a valid response type — is wrapped in a WeixinException with this message plus the original exception's Message appended and InnerException chained.
Solutions
- Log/examine ex.InnerException and the appended ex.Message to see the parse failure
- Dump and validate the raw XML (e.g. XmlDocument.LoadXml) before calling the factory
- Check what the upstream actually returned — a JSON error body means the earlier API call failed; handle that path instead of parsing as XML
Example fix
// before
var msg = WorkResponseMessageBase.CreateFromResponseXml<ResponseMessageText>(rawBody);
// after
if (rawBody.TrimStart().StartsWith("{"))
{
var err = JsonConvert.DeserializeObject<WeixinErrorJson>(rawBody);
throw new WeixinException($"API error {err.errcode}: {err.errmsg}");
}
var msg = WorkResponseMessageBase.CreateFromResponseXml<ResponseMessageText>(rawBody); Defensive patterns
Strategy: try-catch
Validate before calling
try { var doc = new XmlDocument(); doc.LoadXml(xml); }
catch (XmlException ex) { throw new WeixinException("Response XML is not well-formed", ex); } Try / catch
try { var msg = WorkResponseMessageBase.CreateFromResponseXml<T>(xml); }
catch (WeixinException ex) { log.Error($"CreateFromResponseXml failed: {ex.Message}", ex.InnerException); throw; } Prevention
- Check whether upstream returned a JSON error body before parsing as XML
- Validate the XML with XmlDocument.LoadXml during development against real responses
- Keep SDK versions aligned with the API schema you consume
When it happens
Trigger: Calling CreateFromResponseXml<T>() with an XML string that is not well-formed, does not correspond to T's schema, or with an invalid T; JSON-formatted callback bodies passed where XML is expected.
Common situations: WeChat server returning an error JSON body (e.g. errcode JSON) instead of the expected response XML; truncation by logging proxies; SDK version where the XML schema changed.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- CreateFromRequestMessage过程发生异常
- ResponseMessageBase.CreateFromRequestMessage
- MsgType: 在RequestMessageFactory中没有对应的处理程序!
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/0e9d8aad976fc5f1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Response/WorkResponseMessageBase.cs:167
responseMessage = new ResponseMessageVideo();
break;
case ResponseMsgType.News:
responseMessage = new ResponseMessageNews();
break;
case ResponseMsgType.MpNews:
responseMessage = new ResponseMessageMpNews();
break;
case ResponseMsgType.NoResponse:
responseMessage = new WorkResponseMessageNoResponse();
break;
}
responseMessage.FillEntityWithXml(doc);
return responseMessage;
}
catch (Exception ex)
{
throw new WeixinException("ResponseMessageBase.CreateFromResponseXml<T>过程发生异常!" + ex.Message, ex);
}
}
}
}
View on GitHub (pinned to be573f6f94)