{"record":{"id":"58ed6eb6bb164794","repo":"JeffreySu/WeiXinMPSDK","slug":"typename-methodname","errorCode":null,"errorMessage":"无法找到静态方法: {typeName}.{methodName}","messagePattern":"无法找到静态方法: (.+?)\\.(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs","lineNumber":92,"sourceCode":"        try\n        {\n            var type = Type.GetType(typeName);\n            if (type == null)\n            {\n                // 尝试从当前加载的程序集中查找类型\n                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    {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs#L74-L110","documentation":"After resolving the type, InvokeStaticMethod looks up a public static method by name via type.GetMethod(BindingFlags.Static | BindingFlags.Public). If no such method exists it throws InvalidOperationException naming Type.Method. Only public static parameterless-matching signatures can be found this way.","triggerScenarios":"The method name portion of fullMethodPath is wrong, the method is instance-level or non-public, or overloads exist that GetMethod cannot match unambiguously given the parameters.","commonSituations":"Calling an instance API (e.g. an OAuth API requiring an appSecret parameter object) through the static invoker, method renamed in a newer Senparc version, typo in method name from an MCP tool config.","solutions":["Verify the method exists and is public static on the target type","Check the exact method name for the installed SDK version (renames across versions are common)","If the method is instance-based, obtain an instance first or use an API helper designed for it","If overloads exist, ensure GetMethod can disambiguate or adjust the invocation approach"],"exampleFix":"// before\nInvokeWeixinApiHelper.InvokeFullMethod(\"Senparc.Weixin.MP.CommonApi.GetTokn\", args); // typo\n// after\nInvokeWeixinApiHelper.InvokeFullMethod(\"Senparc.Weixin.MP.CommonApi.GetToken\", args);","handlingStrategy":"try-catch","validationCode":"var t = Type.GetType(typeName) ?? AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType(typeName, false)).FirstOrDefault(x => x != null);\nif (t?.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public) == null) throw new InvalidOperationException($\"{typeName}.{methodName} is not a public static method\");","typeGuard":null,"tryCatchPattern":"try { var result = InvokeWeixinApiHelper.InvokeFullMethod(methodPath, args); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"无法找到静态方法\")) { log.Error($\"Method '{methodPath}' is not public static or was renamed\"); }","preventionTips":["Verify target methods are public static before registering tools","Regenerate tool definitions after SDK upgrades","Watch for instance-only APIs that need a wrapper"],"tags":["reflection","method-not-found","mcp","binding-flags"],"backgroundTag":"method-not-found","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"}