JeffreySu/WeiXinMPSDK · error · ArgumentException

方法路径不能为空

Error message

方法路径不能为空

What it means

ParseFullMethodPath splits a full method path like "Namespace.Type.Method" into a type name and method name. If the supplied fullMethodPath is null or an empty string it throws ArgumentException. It is the first validation step used by InvokeFullMethod/InvokeFullMethodAsync in the MCP server.

Solutions

  1. Pass a complete method path such as "Senparc.Weixin.MP.CommonApi.GetToken"
  2. Validate the methodPath from the incoming request before invoking (string.IsNullOrWhiteSpace check)
  3. Fix the MCP client/tool registration so the method path parameter is always supplied

Example fix

// before
var result = InvokeWeixinApiHelper.InvokeFullMethod(null, "GetToken");
// after
string methodPath = "Senparc.Weixin.MP.CommonApi.GetToken";
if (string.IsNullOrWhiteSpace(methodPath)) throw new ArgumentException("methodPath required");
var result = InvokeWeixinApiHelper.InvokeFullMethod(methodPath, new object[0]);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(fullMethodPath)) throw new ArgumentException("fullMethodPath is required");

Try / catch

try { var result = InvokeWeixinApiHelper.InvokeFullMethod(fullMethodPath, args); }
catch (ArgumentException ex) when (ex.ParamName == "fullMethodPath") { log.Error("MCP request missing method path"); }

Prevention

When it happens

Trigger: Calling InvokeFullMethod or InvokeFullMethodAsync with a null, empty, or whitespace-only fullMethodPath string — e.g. an MCP tool request whose method-path field is missing.

Common situations: Malformed MCP client request payloads where the method path parameter is absent, deserialization producing null for an omitted field, copy-paste mistakes leaving the argument empty.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs:53

    /// </summary>
    /// <param name="fullMethodPath">完整方法路径,如 "Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendTextAsync"</param>
    /// <param name="parameters">方法参数</param>
    /// <returns>方法执行结果</returns>
    public async Task<object> InvokeFullMethodAsync(string fullMethodPath, object[] parameters)
    {
        var (typeName, methodName) = ParseFullMethodPath(fullMethodPath);
        return await InvokeStaticMethodAsync(typeName, methodName, parameters);
    }

    /// <summary>
    /// 解析完整方法路径,分离类型名和方法名
    /// </summary>
    /// <param name="fullMethodPath">完整方法路径</param>
    /// <returns>类型名和方法名的元组</returns>
    private (string typeName, string methodName) ParseFullMethodPath(string fullMethodPath)
    {
        if (string.IsNullOrEmpty(fullMethodPath))
            throw new ArgumentException("方法路径不能为空", nameof(fullMethodPath));

        var lastDotIndex = fullMethodPath.LastIndexOf('.');
        if (lastDotIndex == -1)
            throw new ArgumentException("无效的方法路径格式", nameof(fullMethodPath));

        var typeName = fullMethodPath.Substring(0, lastDotIndex);
        var methodName = fullMethodPath.Substring(lastDotIndex + 1);

        return (typeName, methodName);
    }

    /// <summary>
    /// 调用静态方法
    /// </summary>
    /// <param name="typeName">类型名称</param>
    /// <param name="methodName">方法名称</param>
    /// <param name="parameters">参数</param>
    /// <returns>方法执行结果</returns>

View on GitHub (pinned to be573f6f94)