{"record":{"id":"1b20569ec4993348","repo":"JeffreySu/WeiXinMPSDK","slug":"typename-methodname-invokeweixinapihelper","errorCode":null,"errorMessage":"调用方法 {typeName}.{methodName} 时发生错误","messagePattern":"调用方法 (.+?)\\.(.+?) 时发生错误","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs","lineNumber":98,"sourceCode":"                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())\n                {\n                    type = assembly.GetType(typeName);\n                    if (type != null) break;\n                }\n            }\n\n            if (type == null)\n                throw new InvalidOperationException($\"无法找到类型: {typeName}\");\n\n            var method = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);\n            if (method == null)\n                throw new InvalidOperationException($\"无法找到静态方法: {typeName}.{methodName}\");\n\n            return method.Invoke(null, parameters);\n        }\n        catch (Exception ex)\n        {\n            throw new InvalidOperationException($\"调用方法 {typeName}.{methodName} 时发生错误\", ex);\n        }\n    }\n\n    /// <summary>\n    /// 异步调用静态方法\n    /// </summary>\n    /// <param name=\"typeName\">类型名称</param>\n    /// <param name=\"methodName\">方法名称</param>\n    /// <param name=\"parameters\">参数</param>\n    /// <returns>方法执行结果</returns>\n    public async Task<object> InvokeStaticMethodAsync(string typeName, string methodName, object[] parameters)\n    {\n        try\n        {\n            var type = Type.GetType(typeName);\n            if (type == null)\n            {\n                // 尝试从当前加载的程序集中查找类型","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs#L80-L116","documentation":"InvokeStaticMethod wraps the whole reflection invocation in a try/catch and rethrows any exception as InvalidOperationException(\"调用方法 Type.Method 时发生错误\", innerException). The real failure — thrown by the target method, a TargetInvocationException, or an argument binding problem — is in InnerException.","triggerScenarios":"The invoked static method itself throws (network errors, missing config like appSecret, invalid parameters), or arguments do not match the method signature so MethodInfo.Invoke throws TargetInvocationException/ArgumentException.","commonSituations":"WeChat API calls failing due to missing/invalid app credentials, passing wrong parameter count or types to the reflected method, timeouts or access-token errors inside the target API method.","solutions":["Inspect the InnerException of this InvalidOperationException for the root cause","Verify the parameters array matches the target method's signature exactly (count, types, order)","Ensure Senparc.Weixin config (appSecret, token, etc.) is registered before invoking API methods","Check logs/HTTP result of the underlying WeChat call (e.g. errcode returned by the API)"],"exampleFix":"// before\ncatch (InvalidOperationException ex) { log(ex.Message); }\n// after\ncatch (InvalidOperationException ex)\n{\n    log(ex.Message);\n    if (ex.InnerException != null) log(\"Root cause: \" + ex.InnerException); // inspect inner for real error\n}","handlingStrategy":"try-catch","validationCode":"var m = Type.GetType(typeName)?.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);\nif (m != null && m.GetParameters().Length != parameters.Length) throw new ArgumentException(\"Parameter count does not match target method\");","typeGuard":null,"tryCatchPattern":"try { var result = InvokeWeixinApiHelper.InvokeFullMethod(methodPath, args); }\ncatch (InvalidOperationException ex) { log.Error(ex, \"Invoke failed for {0}\", methodPath); if (ex.InnerException != null) HandleRootCause(ex.InnerException); }","preventionTips":["Always unwrap InnerException to find the real failure","Validate parameter types/count against the method signature","Ensure Senparc config (appSecret, token) is registered before API calls"],"tags":["reflection","invocation-failure","mcp","inner-exception"],"backgroundTag":"api-request-failed","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}