JeffreySu/WeiXinMPSDK · error · ArgumentException

无效的方法路径格式

Error message

无效的方法路径格式

What it means

ParseFullMethodPath requires the method path to contain at least one dot separating type name from method name. If fullMethodPath has no '.', it throws ArgumentException with this message. This enforces the "Namespace.Type.Method" format expected by the reflection-based invoker.

Solutions

  1. Supply the fully-qualified path including namespace, type and method separated by dots
  2. Inspect the incoming value and log it to confirm it contains a dot
  3. On the caller side, compose the path from typeFullName + "." + methodName

Example fix

// before
InvokeWeixinApiHelper.InvokeFullMethod("GetToken", args);
// after
InvokeWeixinApiHelper.InvokeFullMethod("Senparc.Weixin.MP.CommonApi.GetToken", args);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(methodPath) || !methodPath.Contains('.')) throw new ArgumentException("methodPath must be 'Namespace.Type.Method'");

Try / catch

try { var result = InvokeWeixinApiHelper.InvokeFullMethodAsync(methodPath, args); }
catch (ArgumentException ex) when (ex.Message.Contains("无效的方法路径格式")) { log.Error($"Invalid method path '{methodPath}', expected Namespace.Type.Method"); }

Prevention

When it happens

Trigger: Passing a path without a dot, e.g. "GetToken" or "CommonApi" instead of "Senparc.Weixin.MP.CommonApi.GetToken" to InvokeFullMethod/InvokeFullMethodAsync.

Common situations: Clients sending only the method name, confusion about the required fully-qualified format, building the path dynamically and dropping the namespace portion.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

    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>
    public object InvokeStaticMethod(string typeName, string methodName, object[] parameters)
    {
        try
        {

View on GitHub (pinned to be573f6f94)