C# – get “Cannot resolve symbol ‘CreatePerOwinContext'”

asp.netcowinself-hosting

I have a self hosted owin Web Api and I'm trying to use a single instance of my EF Context per Owin Request. Here is my config code for the startup class.

public void Configuration(IAppBuilder app)
{         
    app.CreatePerOwinContext(A3Context.Create);
}

This won't build because I get the following error.

Error

5 'Owin.IAppBuilder' does not contain a definition for
'CreatePerOwinContext' and no extension method 'CreatePerOwinContext'
accepting a first argument of type 'Owin.IAppBuilder' could be found
(are you missing a using directive or an assembly reference?)

I'm I missing a reference that I'm not aware of?

Best Answer

CreatePerOwinContext is an extension method in the Microsoft.AspNet.Identity.Owin NuGet package.

To resolve, open package manager console for your project and install with the following command:

Install-Package Microsoft.AspNet.Identity.Owin

Ensure you are referencing the namespace containing the extension method:

using Owin;