{"record":{"id":"e36af3eaa3f2c660","repo":"JeffreySu/WeiXinMPSDK","slug":"typename","errorCode":null,"errorMessage":"无法找到类型: {typeName}","messagePattern":"无法找到类型: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs","lineNumber":88,"sourceCode":"    /// <param name=\"parameters\">参数</param>\n    /// <returns>方法执行结果</returns>\n    public object InvokeStaticMethod(string typeName, string methodName, object[] parameters)\n    {\n        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>","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.MCP.Server/InvokeWeixinApiHelper.cs#L70-L106","documentation":"InvokeStaticMethod resolves the type portion of a full method path by searching loaded assemblies via Assembly.GetType. When no assembly exposes a type matching typeName it throws InvalidOperationException with the type name. This happens before any method lookup, so the failure is purely type resolution.","triggerScenarios":"Calling InvokeFullMethod with a type name that is misspelled, not namespace-qualified, lives in an assembly that is not loaded into the AppDomain, or differs across library versions.","commonSituations":"Renamed classes after a Senparc SDK version upgrade, forgetting a namespace prefix, targeting a type in a NuGet package not referenced/loaded by the MCP server host, generic or nested types needing assembly-qualified names.","solutions":["Use the fully-qualified type name including namespace (e.g. Senparc.Weixin.MP.CommonApi)","Ensure the assembly containing the type is referenced and loaded before invoking (or register it so Assembly.Load resolves it)","Check the exact class name against the installed Senparc SDK version (names change between versions)","For nested/generic types, pass the runtime-correct name (e.g. Namespace.Outer+Inner)"],"exampleFix":"// before\nInvokeWeixinApiHelper.InvokeFullMethod(\"CommonApi.GetToken\", args);\n// after\nInvokeWeixinApiHelper.InvokeFullMethod(\"Senparc.Weixin.MP.CommonApi.GetToken\", args);","handlingStrategy":"try-catch","validationCode":"var type = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType(typeName, false)).FirstOrDefault(t => t != null);\nif (type == null) throw new InvalidOperationException($\"Type '{typeName}' not loaded — check spelling, namespace and project references\");","typeGuard":null,"tryCatchPattern":"try { var result = InvokeWeixinApiHelper.InvokeFullMethod(methodPath, args); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"无法找到类型\")) { log.Error($\"Unknown type in '{methodPath}': check SDK version and references\"); }","preventionTips":["Always use fully-qualified type names","Pin and document the Senparc SDK version the tool paths were generated for","Reference every package whose types the MCP server exposes"],"tags":["reflection","type-resolution","mcp","assembly"],"backgroundTag":"class-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"}