I've been trying without success to get ASP Web API / Autofac integration working. I've created a simple project with one Controller returning a string and am able to run the application successfully. However, when I integrate Autofac into the solution, at runtime I receive a System.EntryPointNotFoundException: Entry point was not found.
Here are the library versions included in the project when I create it on my machine (minus the Autofac libs). I get the Autofac libs from Nuget, all other libs are locally installed.
I put the Autofac code in my Register method like this:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
//Other code left out for brevity
var builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// Set the dependency resolver to be Autofac.
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
}
I receive an EntryPointNotFoundException
in the Application_Start method:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
So then I upgrade ALL the packages via Nuget and get these versions:
And this section is now inserted into the web.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
When I run the application again, I still receive System.EntryPointNotFoundException: Entry point was not found.
What am I missing here to get Autofac and Web API to play nicely together?
Thanks, Kyle
I figured out the issue. You need to make sure the version of Autofac is compatible with the version of Web API. In my case, I'm using the Web API 2.2 libs but the Autofac version labeled Autofac ASP.NET Web API Integration. Once I switched to Autofac ASP.NET Web API 2.2 Integration, then my solution worked. A subtle difference no doubt and easy to assume you're using the right version.
Kyle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With