JeffreySu/WeiXinMPSDK · error · ErrorJsonResultException

{errmsg}

Error message

{errmsg}

What it means

GetMenuFromJson throws an ErrorJsonResultException whose message is the remote errmsg string when the query-menu JSON response contains an 'errmsg' key (e.g. the menu does not exist). Instead of a normal result, the library surfaces the WeChat Work API error so callers can distinguish 'no menu' from a parsed menu. Inside the method, this exception is also caught to set finalResult=null, but at the top level it propagates to the caller.

Solutions

  1. Wrap the GetMenu call in try/catch for ErrorJsonResultException and treat it as 'menu not exists' (return null or an empty menu).
  2. Create the menu first via CreateMenu/CreateMenuAsync for the correct agentId before querying it.
  3. Verify agentId/corpId/secret correspond to the app that actually owns a menu.
  4. Check the exception message for specific errcodes (e.g. menu not exist) to branch logic.

Example fix

// before
var menu = CommonApi.GetMenu(token, agentId); // throws when no menu

// after
GetMenuResult menu = null;
try { menu = CommonApi.GetMenu(token, agentId); }
catch (ErrorJsonResultException ex)
{
    // menu does not exist yet
}
Defensive patterns

Strategy: try-catch

Try / catch

try { menu = CommonApi.GetMenu(token, agentId); }
catch (ErrorJsonResultException ex)
{
    // treat as "menu not exists"; menu = null
}

Prevention

When it happens

Trigger: Calling GetMenu (or GetMenuFromJson) for a corp app/agent whose custom menu was never created, or with an agentId that has no menu configured — WeChat Work returns {"errmsg":"..."} and the library throws with that errmsg as the message.

Common situations: Freshly created WeChat Work agent with no menu yet; querying the wrong agentId or secret; environment mismatch (test vs production app) where the target app never had a menu.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/CommonAPIs/CommonApi.Menu.cs:161

                            //按钮,无下级菜单
                            finalResult.menu.button.Add(GetSingleButtonFromJsonObject(fullButton));
                        }
                        else
                        {
                            //二级菜单
                            var subButton = new SubButton(fullButton["name"] as string);
                            finalResult.menu.button.Add(subButton);
                            foreach (var sb in fullButton["sub_button"] as object[])
                            {
                                subButton.sub_button.Add(GetSingleButtonFromJsonObject(sb as Dictionary<string, object>));
                            }
                        }
                    }
                }
                else if (fullResult != null && fullResult.ContainsKey("errmsg"))
                {
                    //菜单不存在
                    throw new ErrorJsonResultException(fullResult["errmsg"] as string, null, null);
                }
            }
            catch (ErrorJsonResultException ex)
            {
                finalResult = null;

                //如果没有惨淡会返回错误代码:46003:menu no exist
            }
            catch (Exception ex)
            {
                //其他异常
                finalResult = null;
            }
            return finalResult;
        }


        /// <summary>

View on GitHub (pinned to be573f6f94)