{"record":{"id":"10db5c65c43d114e","repo":"JeffreySu/WeiXinMPSDK","slug":"msgtype","errorCode":null,"errorMessage":"未知的MsgType请求类型","messagePattern":"未知的MsgType请求类型","errorType":"exception","errorClass":"UnknownRequestMsgTypeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs","lineNumber":108,"sourceCode":"                case RequestMsgType.Video:\n                    ResponseMessage = await OnVideoRequestAsync(RequestMessage as RequestMessageVideo);\n                    break;\n                case RequestMsgType.ShortVideo:\n                    ResponseMessage = await OnShortVideoRequestAsync(RequestMessage as RequestMessageShortVideo);\n                    break;\n                case RequestMsgType.File:\n                    ResponseMessage = await OnFileRequestAsync(RequestMessage as RequestMessageFile);\n                    break;\n                case RequestMsgType.Event:\n                {\n                    var requestMessageText = (RequestMessage as IRequestMessageEventBase).ConvertToRequestMessageText();\n\n                    ResponseMessage = await OnTextOrEventRequestAsync(requestMessageText) ??\n                                      await OnEventRequestAsync(RequestMessage as IRequestMessageEventBase);\n                }\n                    break;\n                default:\n                    throw new UnknownRequestMsgTypeException(\"未知的MsgType请求类型\", null);\n            }\n        }\n\n\n        #region 接收消息方法\n\n        public virtual async Task<IWorkResponseMessageBase> DefaultResponseMessageAsync(\n            IWorkRequestMessageBase requestMessage)\n        {\n            return await Task.FromResult(DefaultResponseMessage(requestMessage)).ConfigureAwait(false);\n        }\n\n        /// <summary>\n        /// 预处理文字或事件类型请求。\n        /// 这个请求是一个比较特殊的请求，通常用于统一处理来自文字或菜单按钮的同一个执行逻辑，\n        /// 会在执行OnTextRequest或OnEventRequest之前触发，具有以下一些特征：\n        /// 1、如果返回null，则继续执行OnTextRequest或OnEventRequest\n        /// 2、如果返回不为null，则终止执行OnTextRequest或OnEventRequest，返回最终ResponseMessage","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs#L90-L126","documentation":"The default branch of BuildResponseMessageAsync's MsgType switch throws UnknownRequestMsgTypeException when the request's MsgType matches no handled case. It is the final catch-all guard ensuring every WeCom callback message type is explicitly routed to an On*Request method.","triggerScenarios":"A WeCom callback whose MsgType value is not among the handled cases (Text, Image, Voice, Video, Location, Link, ShortVideo, Event, etc.) reaches BuildResponseMessageAsync — typically a newly introduced MsgType from Tencent or a corrupted/incorrectly deserialized message.","commonSituations":"WeCom adds a new callback message type before the library supports it; custom mock messages used in tests with an invalid MsgType; message decryption/deserialization producing a wrong enum value.","solutions":["Upgrade Senparc.Weixin.Work to the newest release to gain support for the new MsgType","Derive from WorkMessageHandler and override the handler for the new message type if available in the entity model","Wrap BuildResponseMessageAsync / handler execution in a try-catch for UnknownRequestMsgTypeException and log the raw XML for analysis","Inspect the raw callback XML to confirm which MsgType string fails to deserialize to a known enum"],"exampleFix":"// before\nvar result = await handler.BuildResponseMessageAsync();\n// after\ntry { var result = await handler.BuildResponseMessageAsync(); }\ncatch (UnknownRequestMsgTypeException ex) { _logger.LogWarning(ex, \"Unhandled WeCom MsgType: {MsgType}\", postModel.MsgType); }","handlingStrategy":"try-catch","validationCode":"var known = new[]{ RequestMsgType.Text, RequestMsgType.Image, RequestMsgType.Voice, RequestMsgType.Video, RequestMsgType.Location, RequestMsgType.Link, RequestMsgType.ShortVideo, RequestMsgType.Event }; if (!known.Contains(requestMessage.MsgType)) { return null; }","typeGuard":"bool HasKnownMsgType(IRequestMessageBase msg) => Enum.IsDefined(typeof(RequestMsgType), msg.MsgType) && msg.MsgType != RequestMsgType.Unknown;","tryCatchPattern":"try { response = await handler.BuildResponseMessageAsync(); } catch (UnknownRequestMsgTypeException ex) { _logger.LogWarning(ex, \"Unknown MsgType: {MsgType}\", rawMsgType); return Content(\"success\"); }","preventionTips":["Upgrade the SDK whenever WeCom announces new callback message types","Validate Token/EncodingAESKey so MsgType is not corrupted during decryption","Log raw callback XML for every unhandled type","Acknowledge unknown callbacks with 'success' to avoid WeCom retry storms"],"tags":["wechat-work","message-handler","unknown-message-type"],"backgroundTag":"unsupported-enum-value","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"}