Closed tillig closed 8 years ago
This is like a year old, and I'm sorry it's taken so long to look into it.
Given the setup, I see the use of GlobalConfiguration.Configuration
when trying to run things in OWIN. That's a pretty common error and is documented here
If the code otherwise works but fails when switching to a more pure-OWIN situation, I'd guess it has to do with that.
I'm going to close this for now, but if you find that fixing that up doesn't solve the problem, come back and we'll continue looking. I'll probably need a repro if that's the case.
From @SpiegelSoft on January 24, 2015 19:3
This is similar to Issue https://github.com/autofac/Autofac/issues/561, but I think I have an accurate way to reproduce it.
Using Autofac.WebApi2, Version 3.4.0.
Because of the rules around SignalR integration, it is recommended to set up the container in the Owin startup pipeline.
Create a new web project, and add Microsoft.Owin.Host.SystemWeb.
Add a new file, called Startup.cs, containing the following content:
using System.Reflection; using System.Web.Http; using Autofac; using Autofac.Integration.WebApi; using Microsoft.Owin; using Owin; using SpiegelSoftUsers;
[assembly: OwinStartup(typeof(Startup))]
namespace MyWebApp { public class Startup { public void Configuration(IAppBuilder appBuilder) { var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly()); var config = GlobalConfiguration.Configuration; containerBuilder.RegisterWebApiFilterProvider(config); var container = containerBuilder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); } } }
Run the web app, and navigate to /odata.
The result is
{ "error":{ "code":"","message":"An error has occurred.","innererror":{ "message":"Object reference not set to an instance of an object.","type":"System.NullReferenceException","stacktrace":" at Autofac.Integration.WebApi.AutofacWebApiFilterProvider.GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.Controllers.HttpActionDescriptor.b0(IFilterProvider fp)\r\n at System.Linq.Enumerable.d 14d0.MoveNext()\r\n at System.Linq.Bufferd a0d__1.MoveNext()"
}
}
}
2.MoveNext()\r\n at System.Linq.Buffer
1..ctor(IEnumerable1 source)\r\n at System.Linq.OrderedEnumerable
1.1..ctor(IEnumerable
1 source)\r\n at System.Linq.Enumerable.1.MoveNext()\r\n at System.Web.Http.Controllers.HttpActionDescriptor.<RemoveDuplicates>d__3.MoveNext()\r\n at System.Linq.Buffer
1..ctor(IEnumerable1 source)\r\n at System.Linq.Enumerable.<ReverseIterator>d__a0
1.MoveNext()\r\n at System.Collections.Generic.List1..ctor(IEnumerable
1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)\r\n at System.Web.Http.Controllers.HttpActionDescriptor.InitializeFilterPipeline()\r\n at System.Lazy
1.CreateValue()\r\n at System.Lazy1.LazyInitValue()\r\n at System.Lazy
1.get_Value()\r\n at System.Web.Http.Controllers.HttpActionDescriptor.GetFilterPipeline()\r\n at System.Web.Http.Controllers.HttpActionDescriptor.GetFilterGrouping()\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.If you move all of that setup code into WebApiConfig, the error goes away.
Copied from original issue: autofac/Autofac#617