{"record":{"id":"5d40ecd00544ab2e","repo":"microsoft/autogen","slug":"no-handler-method-found-for-interface-interface","errorCode":null,"errorMessage":"No handler method found for interface {interface_.FullName}","messagePattern":"No handler method found for interface (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core/BaseAgent.cs","lineNumber":74,"sourceCode":"\n        this.handlerInvokers = this.ReflectInvokers();\n    }\n\n    private Dictionary<Type, HandlerInvoker> ReflectInvokers()\n    {\n        Type realType = this.GetType();\n\n        IEnumerable<Type> candidateInterfaces =\n            realType.GetInterfaces()\n                    .Where(i => i.IsGenericType &&\n                            (i.GetGenericTypeDefinition() == typeof(IHandle<>) ||\n                            (i.GetGenericTypeDefinition() == typeof(IHandle<,>))));\n\n        Dictionary<Type, HandlerInvoker> invokers = new();\n        foreach (Type interface_ in candidateInterfaces)\n        {\n            MethodInfo handleAsync = interface_.GetMethod(nameof(IHandle<object>.HandleAsync), BindingFlags.Instance | BindingFlags.Public)\n                                     ?? throw new InvalidOperationException($\"No handler method found for interface {interface_.FullName}\");\n\n            HandlerInvoker invoker = new(handleAsync, this);\n            invokers.Add(interface_.GetGenericArguments()[0], invoker);\n        }\n\n        return invokers;\n    }\n\n    public async ValueTask<object?> OnMessageAsync(object message, MessageContext messageContext)\n    {\n        // Determine type of message, then get handler method and invoke it\n        var messageType = message.GetType();\n        if (this.handlerInvokers.TryGetValue(messageType, out var handlerInvoker))\n        {\n            return await handlerInvoker.InvokeAsync(message, messageContext);\n        }\n\n        return null;","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core/BaseAgent.cs#L56-L92","documentation":"Thrown in BaseAgent's handler-invoker discovery when an IHandle<> or IHandle<,> interface on the agent type does not expose a public instance HandleAsync method via reflection. Because the interfaces are known to define HandleAsync, this is essentially an internal invariant failure — typically triggered by reflection visibility issues or an incompatible interface definition from a mismatched package version.","triggerScenarios":"Agent type implements IHandle<T> from a different assembly version whose HandleAsync signature differs (e.g. parameter count changed); a custom interface definition shadowing IHandle<>; COM/transparent-proxy types where GetMethod does not resolve normally.","commonSituations":"Mixing versions of Microsoft.AutoGen packages so IHandle<T> resolves to different definitions in one type graph; building custom handler abstractions that mimic IHandle<>; rare dynamic-proxy agents.","solutions":["Align all Microsoft.AutoGen package versions across the project so IHandle<>/IHandle<,> come from a single assembly identity","Implement the framework's IHandle<T> interface directly (public HandleAsync) rather than a lookalike interface","Clean bin/obj and restore to eliminate stale mixed-version assemblies"],"exampleFix":"<!-- before -->\n<ItemGroup>\n  <PackageReference Include=\"Microsoft.AutoGen.Core\" Version=\"0.x\" />\n  <PackageReference Include=\"Microsoft.AutoGen.Agents\" Version=\"0.y\" /> <!-- mismatched -->\n</ItemGroup>\n\n<!-- after -->\n<ItemGroup>\n  <PackageReference Include=\"Microsoft.AutoGen.Core\" Version=\"0.z\" />\n  <PackageReference Include=\"Microsoft.AutoGen.Agents\" Version=\"0.z\" />\n</ItemGroup>","handlingStrategy":"try-catch","validationCode":"foreach (var i in typeof(TAgent).GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IHandle<>)))\n{\n    if (i.GetMethod(nameof(IHandle<object>.HandleAsync), BindingFlags.Instance | BindingFlags.Public) is null)\n        throw new InvalidOperationException($\"Handler surface broken on {i.FullName}; check package version alignment\");\n}","typeGuard":null,"tryCatchPattern":"try { var agent = Activator.CreateInstance<TAgent>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"No handler method found\")) { _logger.LogError(ex, \"IHandle contract mismatch; align Microsoft.AutoGen package versions\"); throw; }","preventionTips":["Keep all Microsoft.AutoGen package versions identical","Implement framework IHandle<T> interfaces directly, not lookalikes"],"tags":["reflection","handlers","version-mismatch","invariant"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}