Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find namespace System.IdentityModel.Services

I'm trying to provide user authentication by implementing UserNamePasswordValidator. I have added Microsoft.IdentityModel and System.IdentityModel.Tokens.ValidatingIssuerNameRegistry nuget packages.

I'm getting and error when I implement UserNamePasswordValidator in my class UserAuthentication saying

The type or namespace name Selectors does not exist in namespace System.IdentityModel (are you missing some reference).

Why is this failing?

public class UserAuthentication : System.IdentityModel.Selectors.UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        try
        {
            if (userName == "test" && password == "test123")
            {
                Console.WriteLine("Authentic User");
            }
        }
        catch (Exception ex)
        {
            throw new FaultException("Unknown Username or Incorrect Password");
        }
    }
}
like image 341
Leo Avatar asked Jul 05 '17 08:07

Leo


1 Answers

Adding the nuget package is not enough (and also in your case, unnecessary), you need to reference the dll in your project. Look for the References list in the solution explorer.

Right click -> Add Reference -> type System.IdentityModel to search box -> select the right dll -> click OK -> Good to go

like image 170
Tamás Szabó Avatar answered Nov 16 '22 12:11

Tamás Szabó