kabaros
kabaros

Reputation: 5173

Autofac.Webapi failing at runtime on application start

I am trying to use Autofac.WebApi with an ASP.NET MVC4 WebApi project. I installed the latest Autofac and Autofac.WebApi using Nuget, but at runtime on application start when trying to register the GlobalConfiguration DependencyResolver, I get this exception thrown:

Could not load file or assembly 'Autofac, Version=2.6.2.859, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Upvotes: 1

Views: 1248

Answers (2)

Alex Meyer-Gleaves
Alex Meyer-Gleaves

Reputation: 3831

There is a matching 2.6.3 package for Autofac.WebApi but it is marked as prerelease. Use the command below to install the prerelease version. That will prevent you from having to add the binding redirect.

Install-Package Autofac.WebApi -Pre

Upvotes: 2

kabaros
kabaros

Reputation: 5173

The latest version of Autofac is 2.6.3 while Autofac.WebApi is on 2.6.2. It seems that Autofac.WebApi tries to call the specific version 2.6.2 but can't find it. I had bindingRedirect in my web.config from any version to 2.6.3 but the problem was still happening.

To solve the issue, I uninstalled both packages then installed Autofac specifying version 2.6.2 and Autofac.WebApi ignoring dependencies (otherwise it will uninstall old autofac and install 2.6.3).

Install-Package autofac -version 2.6.2.859
Install-Package autofac.WebApi -version 2.6.2.859 -IgnoreDependencies

Upvotes: 2

Related Questions