1

I get the following error on my page:

Server Error in '/' Application.

The current type, Microsoft.Owin.Security.IAuthenticationManager, is an interface and cannot be constructed. Are you missing a type mapping? 

I founded out that I should put this code in Unityconfig.cs to resolve this problem:

container.RegisterType<IAuthenticationManager>(
            new InjectionFactory(
                o => System.Web.HttpContext.Current.GetOwinContext().Authentication
            )
        );

But the problem is that the IAuthenticationManager is not visible enter image description here

although I have added the Owin.Security as reference, I have the

using Microsoft.Owin.Security;

Can you please give me some hints?

Liam
  • 27,717
  • 28
  • 128
  • 190
Orsi
  • 545
  • 2
  • 10
  • 27
  • And your referencing the `Microsoft.Owin.Security` dll? – Liam Feb 13 '18 at 11:52
  • yes, I have added the reference – Orsi Feb 13 '18 at 11:53
  • Does it error if you run it? What error do you get? Or will it not build? It could just be intellisense not working correctly. – Liam Feb 13 '18 at 11:54
  • It builds the application. When I run and I want to enter on a page, I get the error:The current type, Microsoft.Owin.Security.AuthenticationManager, is an interface and cannot be constructed. Are you missing a type mapping? – Orsi Feb 13 '18 at 11:55
  • Possible duplicate of [Register IAuthenticationManager with Unity](https://stackoverflow.com/questions/24731426/register-iauthenticationmanager-with-unity) – Liam Feb 13 '18 at 11:56
  • [What you have should work](https://stackoverflow.com/a/26546453/542251). If it doesn't then there is something that your not explaining. If you didn't have the dll referenced then you wouldn't be able to build. I can't see anything in that code to produce the error your saying is happening, so I'm guessing that error is thrown somewhere else? – Liam Feb 13 '18 at 11:57
  • 2
    Do you have a reference to `Microsoft.Owin.dll`? As you can see from [the docs](https://msdn.microsoft.com/en-us/library/microsoft.owin.security.iauthenticationmanager(v=vs.113).aspx), that is where this interface lives. Worth checking that namespace doesn't always equate to the assembly @Liam :) – DavidG Feb 13 '18 at 12:01
  • Thank you @DavidG! This was the problem. I just had the reference to Microsoft.Owin.Security. – Orsi Feb 13 '18 at 12:07

1 Answers1

4

Note that the interface you are trying to use (Microsoft.Owin.Security.IAuthenticationManager) isn't in Microsoft.Owin.Security.dll but is actually in Microsoft.Owin.dll. Check the two lines at the top that tell you both the namespace and the assembly. So you just need to add a reference to that assembly.

For situations like this, it's always worth checking the docs as the namespace doesn't always equate to the assembly name.

DavidG
  • 113,891
  • 12
  • 217
  • 223