autofac / Autofac.WebApi

ASP.NET Web API integration for Autofac
Other
36 stars 27 forks source link

Dependency Issue on latest version on nuget #33

Closed Ncage1974 closed 6 years ago

Ncage1974 commented 6 years ago

There is some type of dependency issue with the latest version of Autofac.WebApi2 (https://www.nuget.org/packages/Autofac.WebApi2/) on nuget. According to nuget these are the dependencies:

Autofac (>= 3.5.0 && < 5.0.0) Microsoft.AspNet.WebApi.Core (>= 5.2.0 && < 6.0.0) Newtonsoft.Json (>= 5.0.8)

I already had Autofac 4.6.2 installed before i installed the package. Here is the error i get: image

System.IO.FileLoadException: 'Could not load file or assembly 'Autofac, Version=3.5.0.0, 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)'

Playing around with versions of autofac it appears that 3.5.0 or 3.5.2 will work but as soon as you upgrade to >= 4.0.0 then you will get the error but according to the dependencies above it should work. I'm using .Net framework 4.6

Edit: Now i'm kind of stuck because Autofac.Mvc5 requires >=4.0.1 && < 5.0.0.

tillig commented 6 years ago

Have you ensured that your web.config has the right binding redirect to point to the newer Autofac? NuGet can sometimes mess them up.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Autofac"
                                  publicKeyToken="17863af14b0044da"
                                  culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.6.2.0"
                                 newVersion="4.6.2.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

See the two occurrences of 4.6.2.0 in there? Make sure those are the version of Autofac you're actually referencing. (Like, if you're using 4.6.0 then make those 4.6.0.0 in both spots.)

Ncage1974 commented 6 years ago

@tillig thank you for the help and yes that did in fact fix the problem. I guess I've been used to nuget taking care of that in the past.