question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Global HttpMessageHandlers don't work with the SwashBuckle HttpMessageHandlers

See original GitHub issue

When I add my own HttpMessageHandler to the MessageHandler collection for an IIS hosted application like so:

GlobalConfiguration.Configuration.MessageHandlers.Add(new AuthenticationHandler());

I can then either hit my standard api endpoints:

e.g.

http://somehost.com/api/companies

OR

I can hit the swagger endpoint.

http://somehost.com/api/swagger

I CANNOT hit one and then the other.

If I hit one of those endpoints and then try to hit the other endpoint I get the following:

Server Error in '/api' Application.

The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'AuthenticationHandler' is not null.
Parameter name: handlers

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'AuthenticationHandler' is not null.
Parameter name: handlers

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentException: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'AuthenticationHandler' is not null.
Parameter name: handlers]
   System.Net.Http.HttpClientFactory.CreatePipeline(HttpMessageHandler innerHandler, IEnumerable`1 handlers) +380
   System.Web.Http.HttpServer.Initialize() +30
   System.Web.Http.HttpServer.<EnsureInitialized>b__b() +10
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +86
   System.Web.Http.HttpServer.EnsureInitialized() +95
   System.Web.Http.<SendAsync>d__0.MoveNext() +147
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Web.Http.WebHost.<ProcessRequestAsyncCore>d__0.MoveNext() +400
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +60
   System.Web.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
johncrimcommented, Jul 16, 2015

Just to contribute a hopefully helpful insight - this error occurs when you have multiple HttpServers that use a single HttpConfiguration, and the HttpConfiguration has one or more delegating handlers implicitly or explicitly configured.

I explain it in more depth here: http://stackoverflow.com/questions/12008686/webapi-batching-and-delegating-handlers/31445355#31445355

1reaction
cryo75commented, Jan 24, 2017

I’m getting the same problem when adding the custom message handler to the pipeline. When I add the message handler to the routing, it works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Global HttpMessageHandlers don't work with the ...
When I add my own HttpMessageHandler to the MessageHandler collection for an IIS hosted application like so: GlobalConfiguration.Configuration.
Read more >
Global Authorize filter not working with Swagger UI Asp.net ...
1 Answer. Swagger API and UI in Swashbuckle are implemented as HttpMessageHandler for route. So filters doesn't work there (because they work ......
Read more >
Creating and Using HTTP Client SDKs in .NET 6 - InfoQ
In this article, the author explains the process behind developing HTTP Client SDKs in .NET 6. The article also contains a sample SDK ......
Read more >
DI scopes in IHttpClientFactory message handlers don't ...
In this post I discuss how handler DI scopes work in IHttpClientFactory, and how they're different to the request DI scope.
Read more >
HTTP Message Handlers in ASP.NET Web API
Message handlers derive from the abstract HttpMessageHandler class. ... To write a custom message handler, derive from System.Net.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found