Why do I get "Cannot resolve symbol 'CreatePerOwinContext'"?
Asked Answered
T

1

12

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?

Throng answered 2/1, 2015 at 1:30 Comment(2)
Similar problem? #23057959Conjoin
I don't think so. None of the versions that I'm using match those mentioned in your link.Throng
R
21

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;
Roble answered 11/3, 2015 at 0:6 Comment(6)
Same error but...."Web already has a reference to 'Microsoft.AspNet.Identity.Owin 2.2.1'."Accurate
Resharper gave me the option to add a reference to the dll and it worked. Must have been a mix up in the project.Accurate
@IanWarburton - Glad you got it cleared up. That error means the package is already in the packages.config for the project you are running the command on. One thing to be aware of is that if you have multiple projects, each project that calls this code needs to have that package in its own packages.config. Resharper will not do that bit for you, it just copies the DLL reference. This means, on a fresh checkout, nuget will not restore the solution to a building state. If the DLL has it you just need to ensure you have "using Owin;" namespace to access the extension method.Roble
Resharper ought to run nuget or at least update the packages files.Accurate
With ASP.NET 5 (DNX 4.5.1) I can add the package and reference but still there's no Owin extension for IApplicationBuilder (which I assume was called IAppBuilder previously), @cchamberlain?Tew
@ThomasHagström I'm not sure as I'm not running anything with that setup and don't have time to set it up at the moment. It doesn't look like there is any info on google for it. Might try some of the newer answers on #23057959 that use IApplicationBuilder and see if they help.Roble

© 2022 - 2024 — McMap. All rights reserved.