{"record":{"id":"93443c3341578265","repo":"JeffreySu/WeiXinMPSDK","slug":"irequestmessagefile","errorCode":null,"errorMessage":"微信公众号不支持 IRequestMessageFile 请求类型","messagePattern":"微信公众号不支持 IRequestMessageFile 请求类型","errorType":"exception","errorClass":"MessageHandlerException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/MessageHandlers/WxOpenMessageEntityEnlightener.cs","lineNumber":24,"sourceCode":"namespace Senparc.Weixin.WxOpen.MessageHandlers\n{\n    public class WxOpenMessageEntityEnlightener : MessageEntityEnlightener\n    {\n        public static MessageEntityEnlightener Instance = new WxOpenMessageEntityEnlightener(NeuChar.PlatformType.WeChat_MiniProgram);\n\n\n        WxOpenMessageEntityEnlightener(NeuChar.PlatformType platformType) : base(platformType) { }\n\n        //TODO:加入 MiniProgramPage类型\n\n        public override IRequestMessageEvent NewRequestMessageEvent()\n        {\n            return new RequestMessageEventBase();\n        }\n\n        public override IRequestMessageFile NewRequestMessageFile()\n        {\n            throw new MessageHandlerException(\"微信公众号不支持 IRequestMessageFile 请求类型\");\n        }\n\n        public override IRequestMessageImage NewRequestMessageImage()\n        {\n            return new RequestMessageImage();\n        }\n\n        public override IRequestMessageLink NewRequestMessageLink()\n        {\n            throw new MessageHandlerException(\"微信公众号不支持 IRequestMessageLink 请求类型\");\n        }\n\n        public override IRequestMessageLocation NewRequestMessageLocation()\n        {\n            throw new MessageHandlerException(\"微信公众号不支持 IRequestMessageLocation 请求类型\");\n        }\n\n        public override IRequestMessageShortVideo NewRequestMessageShortVideo()","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/MessageHandlers/WxOpenMessageEntityEnlightener.cs#L6-L42","documentation":"WxOpenMessageEntityEnlightener.NewRequestMessageFile overrides the factory method only to throw MessageHandlerException, because mini-program (WxOpen) message callbacks never deliver file messages — the enlightener is modeled on the OfficialAccount interface where file requests exist. Hitting this means a file-type message reached a WxOpen message handler.","triggerScenarios":"A message POST with MsgType=file routed to WxOpenMessageHandler; usually caused by misrouting OfficialAccount callbacks to the WxOpen handler, or manually invoking NewRequestMessageFile.","commonSituations":"Shared callback URL configured for both public account and mini program; custom code that reuses the enlightener across account types; unit tests exercising all factory methods.","solutions":["Route file-type messages to the OfficialAccount MessageHandler instead of the WxOpen one","Don't send/forward file messages to mini-program callback endpoints; WeChat mini programs don't push file messages","Wrap message processing in try-catch on MessageHandlerException and log/skip unsupported request types","If you need file handling, create a custom enlightener/handler subclass overriding NewRequestMessageFile with your own implementation"],"exampleFix":"// before\nvar result = await wxOpenMessageHandler.ExecuteAsync(xml); // file message -> throws\n// after\nif (requestMsgType == RequestMsgType.File) {\n    return await officialAccountHandler.ExecuteAsync(xml); // route to correct handler\n}\nvar result = await wxOpenMessageHandler.ExecuteAsync(xml);","handlingStrategy":"try-catch","validationCode":"if (requestMsgType == RequestMsgType.File) {\n    return officialAccountHandler.ExecuteAsync(xml); // WxOpen cannot handle file messages\n}","typeGuard":"bool WxOpenSupportsType(RequestMsgType t) => t is RequestMsgType.Text or RequestMsgType.Image or RequestMsgType.Event;","tryCatchPattern":"try {\n    return await wxOpenHandler.ExecuteAsync(xml);\n} catch (MessageHandlerException ex) when (ex.Message.Contains(\"IRequestMessageFile\")) {\n    logger.LogWarning(\"File message sent to WxOpen handler; ignoring\");\n    return new WeixinResult(\"success\");\n}","preventionTips":["Use separate callback endpoints/handlers for公众号 and小程序","Mini programs never push file messages — treat such traffic as misrouted","Filter unsupported MsgTypes before dispatching to the WxOpen handler","Respond 'success' to unsupported callbacks so WeChat does not retry"],"tags":["weixin","wxopen","message-handler","file-message","unsupported"],"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"}