JeffreySu/WeiXinMPSDK · error · WeixinMenuException
{ex.Message}
Error message
{ex.Message} What it means
GetMenuFromJsonResult wraps ANY exception thrown while converting the full menu JSON into the button graph in a WeixinMenuException whose message is the original ex.Message. This includes the key-validation errors, JSON/serializer failures, and unexpected null structures. It is a catch-all so callers only need to handle WeixinMenuException, but the message may be less specific than the underlying cause.
Solutions
- Catch WeixinMenuException and inspect both the message and the InnerException to find the real cause.
- Log the raw menu JSON (jsonString passed to GetMenu) to compare against the expected GetMenuResultFull schema.
- Update the Senparc.Weixin.Work package to the latest version in case the server response format changed.
- Fix the underlying menu data so parsing succeeds (valid types, keys, non-null containers).
Example fix
// before
catch (WeixinMenuException ex) { throw ex; }
// after
catch (WeixinMenuException ex)
{
_logger.LogError(ex, "Menu parse failed: {Msg} / {Inner}", ex.Message, ex.InnerException?.Message);
throw;
} Defensive patterns
Strategy: try-catch
Try / catch
try { var result = CommonApi.GetMenu(token, agentId); }
catch (WeixinMenuException ex)
{
// always inspect InnerException — message may be a wrapped cause
Log(ex, ex.InnerException);
} Prevention
- Never discard InnerException when rethrowing WeixinMenuException
- Log the raw menu JSON alongside the exception for diagnosis
- Keep the Senparc.Weixin.Work package updated against API format drift
- Treat menu parse failures as data problems first, code problems second
When it happens
Trigger: Any failure inside GetMenuFromJsonResult (called by GetMenu): malformed/unexpected menu JSON shape, null button containers where the parser expects arrays, or the inner WeixinMenuException key validations bubbling up to the catch block.
Common situations: WeChat Work changes the menu response format; corrupted or truncated JSON stored/returned; developer-supplied menu objects with unexpected nulls during custom parsing; version drift between library expectations and server response.
Related errors
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/00627c59850fbad1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/CommonApi.Menu.cs:439
subButton.sub_button.Add(new SingleScancodeWaitmsgButton()
{
name = subSubButton.name,
key = subSubButton.key,
type = subSubButton.type
});
}
}
}
}
result = new GetMenuResult()
{
menu = bg
};
}
catch (Exception ex)
{
throw new WeixinMenuException(ex.Message, ex);
}
return result;
}
#endregion
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="accessToken">调用接口凭证</param>
/// <param name="agentId">企业应用的id,整型。可在应用的设置页面查看</param>
/// <returns></returns>
public static WorkJsonResult DeleteMenu(string accessTokenOrAppId, int agentId)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/menu/delete?access_token={0}&agentid={1}", accessToken.AsUrlData(), agentId);
var result = CommonJsonSend.Send<WorkJsonResult>(null, url, null, CommonJsonSendType.GET);View on GitHub (pinned to be573f6f94)