autofac/Autofac.Owin

Autofac.Owin 4.2.0 seems to require Microsoft.Owin 3.0.0

Closed this issue · 1 comments

I'm using Autofac.Owin to get DI features using IAppBuilder.
I created a simple DebugMiddleware which I try to resolve from Autofac container by calling the UseMiddlewareFromContainer method.

Here's a simple code snippet:

public void Configuration(IAppBuilder application)
{
        this.RegisterDependencies(); // creating Container here
        application.UseMiddlewareFromContainer<DebuggingMiddleware>(); 
}

DebugMiddleware is a simple OwinMiddleware class that doesn't have any dependencies other than Microsoft.Owin.

The problem is that the Configuration method is not even fired on startup and the app crashes with the exception:

System.IO.FileLoadException
Could not load file or assembly 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I looked up in the source code of Autofac.Owin, the packages.config containts a reference to Microsoft.Owin 3.0.0 even though there's >=3.0.0 on Nuget. Can this be a problem?

Nope, it should be fine. Verify your project has a reference to the Microsoft. Owin package. If it does and it's not 3.0.0 (like if it's higher than that) then you're missing an assembly binding redirect. Examples here. NuGet sometimes forgets to add a redirect to the right Microsoft.Owin version.

Better still, switch to PackageReference and away from packages.config. Here's a working code example using MS.Owin 4.0.1 and PackageReference.