{"record":{"id":"17d7898bc553ae4c","repo":"JeffreySu/WeiXinMPSDK","slug":"iresponsemessagempnews","errorCode":null,"errorMessage":"微信公众号不支持 IResponseMessageMpNews 响应类型","messagePattern":"微信公众号不支持 IResponseMessageMpNews 响应类型","errorType":"exception","errorClass":"MessageHandlerException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.MP/Senparc.Weixin.MP/MessageHandlers/MpMessageEntityEnlightener.cs","lineNumber":76,"sourceCode":"\n        public override IRequestMessageVideo NewRequestMessageVideo()\n        {\n            return new RequestMessageVideo();\n        }\n\n        public override IRequestMessageVoice NewRequestMessageVoice()\n        {\n            return new RequestMessageVoice();\n        }\n\n        public override IResponseMessageImage NewResponseMessageImage()\n        {\n            return new ResponseMessageImage();\n        }\n\n        public override IResponseMessageMpNews NewResponseMessageMpNews()\n        {\n            throw new MessageHandlerException(\"微信公众号不支持 IResponseMessageMpNews 响应类型\");\n        }\n\n        public override IResponseMessageMusic NewResponseMessageMusic()\n        {\n            return new ResponseMessageMusic();\n        }\n\n        public override IResponseMessageNews NewResponseMessageNews()\n        {\n            return new ResponseMessageNews();\n        }\n\n        public override IResponseMessageText NewResponseMessageText()\n        {\n            return new ResponseMessageText();\n        }\n\n        public override IResponseMessageTransfer_Customer_Service NewResponseMessageTransfer_Customer_Service()","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.MP/Senparc.Weixin.MP/MessageHandlers/MpMessageEntityEnlightener.cs#L58-L94","documentation":"MpMessageEntityEnlightener.NewResponseMessageMpNews throws MessageHandlerException because the MP (公众号) channel does not support the mpnews response message type; the enlightener's factory method has no valid IResponseMessageMpNews implementation for this platform. Requesting an mpnews response entity from an MP message handler is by definition an invalid operation for WeChat official accounts.","triggerScenarios":"Code creates a response message via a MessageEntityEnlightener factory, e.g. calling NewResponseMessageMpNews() on an MP handler, or generic/copy-based response construction that iterates response types and includes MpNews for a 公众号 handler (common when code written for 微信企业号/开放平台 is reused on MP).","commonSituations":"Reusing handler/enlightener code across Senparc.Weixin.MP and Senparc.Weixin.Work (企业微信) where mpnews is supported only in Work; generic response-building helpers that don't branch on platform; accidentally selecting ResponseMessageMpNews when replying in a customer-service or passive-reply path.","solutions":["Do not use IResponseMessageMpNews in MP handlers; reply with a supported type (Text, Image, Voice, Video, Music, News, Transfer_Customer_Service).","Branch on platform: only build MpNews responses in contexts where the enlightener supports it (e.g. Senparc.Weixin.Work).","If mpnews content is required for official accounts, use the 客服接口/群发 API (MassApi.SendMpNews) instead of passive message response.","Guard any generic factory loop with a type check that skips/throws-before-use for MpNews on MP."],"exampleFix":"// before\nvar response = enlightener.NewResponseMessageMpNews(); // throws on MP\n\n// after\nIResponseMessageBase response;\nif (supportsMpNews) // e.g. Work platform\n    response = enlightener.NewResponseMessageMpNews();\nelse\n    response = new ResponseMessageText { Content = \"fallback\" };","handlingStrategy":"validation","validationCode":"if (response is IResponseMessageMpNews)\n    throw new InvalidOperationException(\"MpNews responses are not supported on MP; use MassApi.SendMpNews instead.\");","typeGuard":"bool IsMpSupportedResponse(IResponseMessageBase r) =>\n    r is ResponseMessageText or ResponseMessageImage or ResponseMessageVoice\n        or ResponseMessageVideo or ResponseMessageMusic or ResponseMessageNews\n        or ResponseMessageTransfer_Customer_Service;","tryCatchPattern":"try\n{\n    response = enlightener.NewResponseMessageMpNews();\n}\ncatch (MessageHandlerException ex) when (ex.Message.Contains(\"IResponseMessageMpNews\"))\n{\n    response = new ResponseMessageText { Content = \"当前公众号暂不支持该消息类型\" };\n}","preventionTips":["Only use MpNews with Senparc.Weixin.Work (企业微信) contexts, never MP.","For official-account news push, use MassApi (群发接口) or customer-service API.","Centralize response construction in one factory that branches on platform.","Avoid generic loops that instantiate every IResponseMessage type without filtering."],"tags":["wechat","messagehandler","mpnews","unsupported-response-type","platform"],"backgroundTag":"unsupported-operation","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"}