JeffreySu/WeiXinMPSDK · error · WeixinException
CreateFromRequestMessage过程发生异常
Error message
CreateFromRequestMessage过程发生异常
What it means
CreateFromRequestMessage wraps any exception raised while constructing and populating the response message (including the UnknownRequestMsgTypeException from the default case and NullReferenceException if requestMessage is null) inside a WeixinException with this fixed message, chaining the original exception as InnerException.
Solutions
- Inspect ex.InnerException to find the actual cause — this message is only a wrapper
- Null-check the requestMessage before calling CreateFromRequestMessage
- Catch WeixinException around the call and log InnerException with its stack trace
Example fix
// before
catch (WeixinException ex) { log.Error(ex.Message); }
// after
catch (WeixinException ex) { log.Error(ex.Message, ex.InnerException ?? ex); } Defensive patterns
Strategy: try-catch
Validate before calling
if (requestMessage == null)
throw new ArgumentNullException(nameof(requestMessage)); Try / catch
try { var msg = WorkResponseMessageBase.CreateFromRequestMessage(request, msgType); }
catch (WeixinException ex) { log.Error(ex.Message, ex.InnerException); throw ex.InnerException ?? ex; } Prevention
- Always log InnerException — this error is only a wrapper
- Null-check requestMessage before the factory call
- Catch WeixinException once at the message-handling boundary instead of per call site
When it happens
Trigger: Any failure inside the factory: requestMessage is null, unmapped ResponseMsgType, or an assignment inside the try block throws.
Common situations: Feeding a null or malformed request entity into the response factory during message handling pipelines; logging code that only reads Message and misses the root cause in InnerException.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- MsgType: 在RequestMessageFactory中没有对应的处理程序!
- RequestMessage转换出错!可能是MsgType不存在!,XML:
- MsgType: 在ResponseMessageFactory中没有对应的处理程序!
- ResponseMsgType没有为 提供对应处理程序。
- ResponseMessageBase.CreateFromRequestMessage
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/01f311474e3494af.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Response/WorkResponseMessageBase.cs:93
break;
case ResponseMsgType.MpNews:
responseMessage = new ResponseMessageMpNews();
break;
case ResponseMsgType.NoResponse:
responseMessage = new WorkResponseMessageNoResponse();
break;
default:
throw new UnknownRequestMsgTypeException(string.Format("ResponseMsgType没有为 {0} 提供对应处理程序。", msgType), new ArgumentOutOfRangeException());
}
responseMessage.ToUserName = requestMessage.FromUserName;
responseMessage.FromUserName = requestMessage.ToUserName;
responseMessage.CreateTime = SystemTime.Now; //使用当前最新时间
}
catch (Exception ex)
{
throw new WeixinException("CreateFromRequestMessage过程发生异常", ex);
}
return responseMessage;
}
/// <summary>
/// 获取响应类型实例,并初始化
/// </summary>
/// <typeparam name="T">需要返回的类型</typeparam>
/// <param name="requestMessage">请求数据</param>
/// <returns></returns>
public static T CreateFromRequestMessage<T>(IWorkRequestMessageBase requestMessage) where T : WorkResponseMessageBase
{
try
{
var tType = typeof(T);
var responseName = tType.Name.Replace("ResponseMessage", ""); //请求名称
ResponseMsgType msgType = (ResponseMsgType)Enum.Parse(typeof(ResponseMsgType), responseName);View on GitHub (pinned to be573f6f94)