I'm having some difficulties with OWIN in setting up ASP.NET WebApi2. The first request after restarting throws an exception:
[ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.HttpMessageInvoker'.]
System.Net.Http.HttpMessageInvoker.CheckDisposed () +327456
System.Net.Http.HttpMessageInvoker.SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) +24
System.Web.Http.Owin. <InvokeCore> d__0.MoveNext () +501
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task) +58
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline. <RunApp> d__5.MoveNext () +187
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task) +58
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline. <DoFinalWork> d__2.MoveNext () +185
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End (IAsyncResult ar) +69
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork (IAsyncResult ar) +64
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute () +483
System.Web.HttpApplication.ExecuteStep (IExecutionStep step, Boolean & completedSynchronously) +157
I believe the problem was caused by a long-term task when it first hit the EF DbContext. In general, the first request is about 4-6000 ms. There are no more exceptions after this first request.
I reproduced the problem in a simplified form using the webapi project and the following run OWIN (and not global.asax):
public class Startup { public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes();
I add a controller:
[Route("api/test/number")] public class TestController : ApiController { public object Get() { return 42; } }
When I request this, the first request throws an exception.
source share