{"record":{"id":"c6c4eda7f831087f","repo":"ThreeMammals/Ocelot","slug":"it-is-not-a-delegating-handler","errorCode":null,"errorMessage":"It is not a delegating handler","messagePattern":"It is not a delegating handler","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/DependencyInjection/OcelotBuilder.cs","lineNumber":278,"sourceCode":"            return new DelegateInvokingLoadBalancerCreator<TLoadBalancer>(Create);\r\n        }\r\n\r\n        Services.AddSingleton<ILoadBalancerCreator>(implementationFactory);\r\n        return this;\r\n    }\r\n\r\n    /// <summary>\r\n    /// Adds a <see cref=\"DelegatingHandler\"/> of the <paramref name=\"delegateType\"/> type as a transient service, with the <paramref name=\"global\"/> option to make the handler globally available.\r\n    /// </summary>\r\n    /// <param name=\"delegateType\">The type of a <see cref=\"DelegatingHandler\"/> to be registered.</param>\r\n    /// <param name=\"global\">True if the handler should be globally available.</param>\r\n    /// <returns>A reference to the same <see cref=\"IOcelotBuilder\"/> object.</returns>\r\n    /// <exception cref=\"ArgumentOutOfRangeException\">Generates an exception if the <paramref name=\"delegateType\"/> type does not inherit from the <see cref=\"DelegatingHandler\"/>.</exception>\r\n    public IOcelotBuilder AddDelegatingHandler(Type delegateType, bool global = false)\r\n    {\r\n        if (!typeof(DelegatingHandler).IsAssignableFrom(delegateType))\r\n        {\r\n            throw new ArgumentOutOfRangeException(nameof(delegateType), delegateType.Name, \"It is not a delegating handler\");\r\n        }\r\n\r\n        if (global)\r\n        {\r\n            Services.AddTransient(delegateType);\r\n            Services.AddTransient(provider =>\r\n            {\r\n                var service = provider.GetService(delegateType) as DelegatingHandler;\r\n                return new GlobalDelegatingHandler(service);\r\n            });\r\n        }\r\n        else\r\n        {\r\n            Services.AddTransient(typeof(DelegatingHandler), delegateType);\r\n        }\r\n\r\n        return this;\r\n    }\r","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/ThreeMammals/Ocelot/blob/d1f22d930430410bfd0233f5e9e4f92980cf7df0/src/DependencyInjection/OcelotBuilder.cs#L260-L296","documentation":"This is a validation guard inside the AddDelegatingHandler fluent method of IOcelotBuilder. The method registers a message-handler type as a transient DelegatingHandler service for Ocelot's HttpClient pipeline; before registering it checks that the supplied delegateType is actually assignable to DelegatingHandler. The input at fault is the caller-supplied delegateType argument: passing any type that does not derive from DelegatingHandler (e.g. a plain HttpClientHandler, an IHttpMessageHandler implementation that is not a DelegatingHandler, or an unrelated type) makes the generic constraint check fail and the error is thrown at DI-registration time, during Ocelot service configuration, before any request is handled.","triggerScenarios":"Thrown at src/DependencyInjection/OcelotBuilder.cs:278 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a Type that derives from System.Net.Http.DelegatingHandler, e.g. typeof(MyDelegatingHandler).","If registering a delegate, use the AddDelegatingHandler(Func<DelegatingHandler>, bool) overload instead of the type-based overload.","Verify with typeof(DelegatingHandler).IsAssignableFrom(delegateType) before calling AddDelegatingHandler.","Ensure generics/assembly loading (e.g. reflection-based plugin loading) resolve to the DelegatingHandler subclass, not a base handler type such as HttpMessageHandler."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d1f22d930430410bfd0233f5e9e4f92980cf7df0","analyzedAt":"2026-09-12T13:50:06.067Z","contentChangedAt":"2026-09-12T13:50:06.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}