Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method?

The following code is copied from the Asp.Net Identity 2.0 sample.

private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
    get
    {
        return // Error 
          _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    }
    private set
    {
        _userManager = value;
    }
}

However it gets the following error?

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

Update:

The version 2 of Microsoft.AspNet.Identity.Owin.dll already exists in ...\packages\Microsoft.AspNet.Identity.Owin.2.0.1\lib\net45.

However, the view definition of HttpContext.GetOwinContext() are different between my project and the sample. The first three lines of my project are

#region Assembly Microsoft.Owin.Host.SystemWeb.dll, v2.0.0.0
// C:\......\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
#endregion

while the sample is

#region Assembly Microsoft.Owin.Host.SystemWeb.dll, v2.1.0.0
// C:\....\sample\packages\Microsoft.Owin.Host.SystemWeb.2.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
#endregion

But I already updated all Owin Nuget packages to the newest version using Neget.

like image 323
ca9163d9 Avatar asked May 08 '14 04:05

ca9163d9


1 Answers

The extension method was moved to a different namespace, try adding

using Microsoft.AspNet.Identity.Owin;
like image 51
Hao Kung Avatar answered Nov 08 '22 15:11

Hao Kung