rwkiii rwkiii - 2 months ago 55
ASP.NET (C#) Question

IOwinContext does not contain a definition for GetUserManager()

I decided to use Account Confirmation and Password Recovery with ASP.NET Identity. I am using Identity 2.1.0. I installed the sample MVC Application from NuGet into an empty project so I could take a look at how it is configured.

After incorporating changes into my project, there is one error I don't understand how to resolve:


'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?) C:\Users\xxxxx\Source\Repos\xxxxxx\xxxxxx\xxxxxx\Controllers\AccountController.cs 48 69 xxx
xxx xxx


The error is being thrown in my AccountController.cs:

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


In the sample application and in my project I see under Properties that both projects have Microsoft.AspNet.Identity.Owin Version 2.0.0.0 installed.

When I right click over GetOwinContext() in my project and Goto Definition, it shows that the metadata is from
Assembly Microsoft.Owin.Host.SystemWeb.dll, v2.1.0.0
, but when I click on
Microsoft.Owin.Host.SystemWeb
under References I see in the Properties that it is only version 2.0.0.0 - not only does this seem strange, but it also differs from the sample application that shows 2.1.0.0. - this is the only difference I can find.


I don't find any differences other than what is in the bolded paragraph above. It seems wrong, but I'm not sure and I don't know how to fix it if it is wrong.

Answer

Right clicking on GetUserManager didn't display the usual Resolve menu item, only Refactor so the issue wasn't obvious, to me anyway... I was able to fix this problem by including a using statement:

using Microsoft.AspNet.Identity.Owin;

:S

Comments