JeffreySu/WeiXinMPSDK · error · MessageHandlerException

微信公众号不支持 IResponseMessageMusic 响应类型

Error message

微信公众号不支持 IResponseMessageMusic 响应类型

What it means

WxOpenMessageEntityEnlightener.NewResponseMessageMusic unconditionally throws MessageHandlerException. Music replies are a 公众号 (MP) response type not supported by the WxOpen Mini Program message pipeline, so the factory throws instead of constructing the entity.

Solutions

  1. Reply with ResponseMessageText or transfer to customer service instead of a music message in WxOpen.
  2. Gate music replies behind a platform check (only in MP handlers).
  3. Push media content via customer-service messages handled on the MP side.

Example fix

// before
var music = enlightener.NewResponseMessageMusic();
// after
var reply = enlightener.NewResponseMessageText();
reply.Content = "请在公众号中查看音乐内容";
Defensive patterns

Strategy: validation

Validate before calling

if (platform == Platform.WxOpen && replyKind == ReplyKind.Music)
    replyKind = ReplyKind.Text; // music replies unsupported in WxOpen

Type guard

static bool IsWxOpenUnsupportedResponse(IResponseMessageBase r) =>
    r is IResponseMessageMusic or IResponseMessageVideo or IResponseMessageVoice or IResponseMessageNews or IResponseMessageImage or IResponseMessageMpNews;

Try / catch

try
{
    var music = enlightener.NewResponseMessageMusic();
}
catch (MessageHandlerException)
{
    var reply = enlightener.NewResponseMessageText(); // fallback
}

Prevention

When it happens

Trigger: Calling NewResponseMessageMusic() on the WxOpen enlightener, typically from a WxOpen On* handler attempting to reply with a music message or shared MP reply code.

Common situations: Porting MP music-reply handlers to WxOpen; generic response factories that create music replies per message type regardless of platform.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12). Data as JSON: /api/errors/cabcff1e017b997d. Report an issue: GitHub.

Appendix: source

Thrown at src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/MessageHandlers/WxOpenMessageEntityEnlightener.cs:74

        public override IRequestMessageVoice NewRequestMessageVoice()
        {
            throw new MessageHandlerException("微信公众号不支持 IRequestMessageVoice 请求类型");
        }

        public override IResponseMessageImage NewResponseMessageImage()
        {
            throw new MessageHandlerException("微信公众号不支持 IResponseMessageImage 响应类型");
        }

        public override IResponseMessageMpNews NewResponseMessageMpNews()
        {
            throw new MessageHandlerException("微信公众号不支持 IResponseMessageMpNews 响应类型");
        }

        public override IResponseMessageMusic NewResponseMessageMusic()
        {
            throw new MessageHandlerException("微信公众号不支持 IResponseMessageMusic 响应类型");
        }

        public override IResponseMessageNews NewResponseMessageNews()
        {
            throw new MessageHandlerException("微信公众号不支持 IResponseMessageNews 响应类型");
        }

        public override IResponseMessageText NewResponseMessageText()
        {
            return new Senparc.Weixin.MP.Entities.ResponseMessageText();
            //throw new MessageHandlerException("微信公众号不支持 IResponseMessageText 响应类型");
        }

        public override IResponseMessageTransfer_Customer_Service NewResponseMessageTransfer_Customer_Service()
        {
            return new ResponseMessageTransfer_Customer_Service();
        }

View on GitHub (pinned to be573f6f94)