1

I'm currently trying to implement an AspNet.Identity Authentication in an AngularJS Single Page App. The weird thing is that in my ApplicationUserManager class , I want to use Microsoft.Owin and Microsoft.AspNet.Identity.Owin but in both cases I get a "cannot resolve symbol 'Owin'" error message.

Does anyone have an idea what is going on? I have included the dependencies in my project.json and downloaded the packages. Simplified version of the ApplicationUserManager class is this:

using Matimez.Models;
using Matimez.Models.Users;
using Microsoft.AspNet.Identity.Owin;  //Error message
using Microsoft.Owin;                  //Error message
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;


public class ApplicationUserManager : UserManager<NewUser>
{ 
    public ApplicationUserManager(IUserStore<NewUser> store)
    : base(store)
        {
        }

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
    var appDbContext = context.Get<MyAppContext>();
    var appUserManager = new ApplicationUserManager(new UserStore<NewUser>(appDbContext));

    return appUserManager;
}
}

Here are the dependencies in my project.json as requested below:

  "dependencies": {
   "EntityFramework": "7.0.0-beta4",
   "EntityFramework.Commands": "7.0.0-beta4",
   "EntityFramework.SqlServer": "7.0.0-beta4",
   "MyApp.Models": "1.0.0-*",
   "MyApp.Services": "1.0.0-*",
   "Microsoft.AspNet.Diagnostics": "1.0.0-beta4",
   "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta4",
   "Microsoft.AspNet.Identity": "3.0.0-beta4",
   "Microsoft.AspNet.Mvc": "6.0.0-beta4",
   "Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
   "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
   "Microsoft.AspNet.StaticFiles": "1.0.0-beta4",
   "Microsoft.AspNet.WebApi.Owin": "5.2.2",
   "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta4",
   "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
   "Microsoft.Framework.Logging": "1.0.0-beta4",
   "Microsoft.Framework.Logging.Console": "1.0.0-beta4",
   "Microsoft.Owin": "3.0.1",
   "Microsoft.Owin.Security": "3.0.1",
   "Microsoft.Owin.Security.Cookies": "3.0.1",
   "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta4",
   "Microsoft.AspNet.Identity.Owin": "2.2.1"

FYI I'm using VS Community 2015

UPDATE:

So thanks to the advice of Behnaz, I installed the necessary packages and apparently that worked. Probably one of them was missing.

However the problem now are ambiguous references for the UserManager class which exists in both Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.Core.

Even though I do not have a Microsoft.AspNet.Identity.Core dependency, Microsoft.AspNet.Identity.Owin...has a reference to it, creating this weird loop. Also removing Microsoft.AspNet.Identity will not work as it is also referenced in Microsoft.AspNet.Identity.EntityFramework. How can I solve this issue?

jimmious
  • 358
  • 3
  • 19

1 Answers1

6

You need to install some packages to be able to use "Owin":

Microsoft.AspNet.Identity.Owin 
Microsoft.AspNet.Identity.EntityFramework 
Microsoft.Owin.Host.SystemWeb 
Microsoft.AspNet.WebApi.Owin 
Microsoft.Owin.Security.OAuth 
Microsoft.Owin.Cors 

From the Tools menu, select Library Package Manager and then click Package Manager Console, then install the packages by using the Install-Package command:

Install-Package Microsoft.AspNet.Identity.Owin 

You can find more information in Adding ASP.NET Identity to an Empty or Existing Web Forms Project.

BenV
  • 12,052
  • 13
  • 64
  • 92
Behnaz Ysfi
  • 111
  • 3
  • Installing these packages worked,thanks. Apparently some one of them was missing. However I am getting ambiguous references for example for IUserStore that can apparently be referenced both from Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.Core. – jimmious Jul 24 '15 at 15:36
  • I think it is because of the versions of the libraries that you installed. As far as I know, classes are changed in different versions. So maybe you are using libraries which are not consistent with each other. I think, you'd better delete all libraries related to "Owin" and "Identity" and then install them again through packages. – Behnaz Ysfi Jul 24 '15 at 16:58
  • It is very hard though to determine the right combination of versions. I'm still battling with the ambiguous reference issue, check this (new) question that I posted here: http://stackoverflow.com/questions/31700074/ambiguous-reference-issue-microsoft-aspnet-identity-microsoft-aspnet-identity – jimmious Jul 29 '15 at 12:25
  • 1
    Great answer. I was trying to set up a blank ASP.NET Web API 2 project from scratch (I recommend first creating the ASP.NET Web API & MVC project as a reference point so you know what classes to create). I had managed to create the required classes, install OWIN etc but it turned out I was missing a few things as per @BehnazYsfi post – Trevor Feb 12 '17 at 16:18