Microsoft.AspNet.Identity.Owin.OwinContextExtensions doesn't seem to work

440 Views Asked by At

I am creating a custom asp.net.identity provider in a separate assembly in order to use it from two different web api 2 projects. I took the default vs2013 template for a web api project as a guide and so far I have implement the required classes. In the separate assembly I am using a user manager class derived from Microsoft.AspNet.Identity.UserManager(Of T) class.

Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)

Now I want to implement the create shared function in order to use as a callback in the CreatePerOwinContext function. According to the template, I am declaring it like this:

Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin

Public Class EzeUserManager
    Inherits UserManager(Of EzeIdentityUser)

... Class Implementation ...

Public Shared Function Create(options As IdentityFactoryOptions(Of EzeUserManager), context As IOwinContext)
    Dim Result As New EzeUserManager(New EzeIdentityUserStore(context.Get(Of EzeLDAPContext)()))

The problem is that

context.Get(Of EzeLDAPContext)()

fails because it requires a key.

From the template I can see that the get method which doesn't require a key is an extension defined in Microsoft.AspNet.Identity.Owin.OwinContextExtensions which I have already installed and referenced through nuget and imported it in the class.

But it doesn't work.

I found that the key is actually the type name of the class so probably I can overcome this problem, however I didn't try it yet because I really want to make the extensions to work.

The question is: Am I missing something here?

Notes: The project in question is a Class Library targeting .NET 4.5.1 with the following references:

Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Security.OAuth
Newtonsoft.Json
Owin
1

There are 1 best solutions below

0
On BEST ANSWER

As I explained in the question, I was using the template generated by VS as a guide. During the implementation process of my project, I had update the nuget packages several times but only in my project not in the template project (same solution) since I was going to deleted it afterwards. This resulted the two projects to reference two different versions of the required assemblies. I don't know how exactly and why this "multi" reference caused this problem but once I updated the template project's nuget packages the problem was resolved.

I hope this helps someone with a similar issue.