I'm having an issue with a WebAPI project hosted on IIS that serves a REST API. The project uses Autofac to take care of creating the controllers. This works fine and has no issues. However, after a certain amount of time (rather long, hard to time it) when the REST API is called the server returns an error. When doing the same call again everything is back to normal. After research I noticed that Autofac couldn't create instances which results in a 500 error (and thus an error message for the end user).
This is the error message returned from the server (which indicates autofac couldn't create the instances.
An error occurred when trying to create a controller of type 'TranslationController'. Make sure that the controller has a parameterless public constructor.
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()
Autofac's WebApi extension is used and works (except from the first load).
This is the module that registers the controllers:
public class WebApiIntegrationModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
}
}
All of the dependencies used by the controllers are in the same assembly, so no other assemblies should be needed to instantiate the controller.
The service actually runs without issues, except that first load. I've been looking around for an answer but I haven't found any. I hope someone here knows where to start looking? This surely has to do something with the initial load of the service in IIS but I cannot see anything wrong. What did I miss?