2

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.

rwkiii
  • 5,716
  • 18
  • 65
  • 114

3 Answers3

8

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

rwkiii
  • 5,716
  • 18
  • 65
  • 114
1

I had some similar issues with the Authentication framework last time I started an MVC project. What solved it for me, was to uninstall the Authentication framwork (via Nuget), and install it again. They recently updated the Authentication framework, but I'm not sure the standard MVC project uses the newly update one. Let me know if it works.

MichaelCleverly
  • 2,473
  • 1
  • 24
  • 33
  • Don't some packages change some source code? I know packages CAN make modifications to source, but I worry that some of my customizations will be overwritten. – rwkiii Jun 30 '14 at 02:27
  • What kind of changes have you made to the authentication classes? Give me 2 seconds, and I will test it for you. – MichaelCleverly Jun 30 '14 at 02:28
  • I don't think I've made any changes OWIN-related. Isn't that mostly what I'm concerned with is OWIN packages? Or would I also want to uninstall and reinstall Identity-related packages? – rwkiii Jun 30 '14 at 02:31
  • When you uninstall the Owin package, it will automatically unstiall all it's depencies, like owin.security and owin.security.cookies. i don't see how any of your work could get lost. – MichaelCleverly Jun 30 '14 at 02:35
  • Uninstalled, cleaned the project and reinstalled everything. Still have the one error. :( – rwkiii Jun 30 '14 at 02:53
  • I searched for `GetUserManager` in Object Viewer and it found `Microsoft.AspNet.Identity.Owin.OwinContextExtensions.GetUserManager(this Microsoft.Owin.IOwinContext)` - I'm not sure if that's what I want to be using. It looks like it, but I wonder why it would be in a different assembly. – rwkiii Jun 30 '14 at 02:59
1

for some reason after doing what's mentioned in the most voted question i had to clean and build the project again for it to work.

Osvaldo Maria
  • 340
  • 5
  • 14