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
My DelegatingHandler returns the base.SendAsync to ensure the next handler is invoked.
return base.SendAsync(request, cancellationToken);
I am running the NuGet pre-alpha version which I think is the Swagger_2.0 git tag.
I'm going to close this issue for now as I can't repro. Please re-open if you have time to troubleshoot further
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
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.
Most helpful comment
Just to contribute a hopefully helpful insight - this error occurs when you have multiple
HttpServers that use a singleHttpConfiguration, and theHttpConfigurationhas 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