I want to override the method IUserStore FindByNameAsync. The method is used in the CreateAsyncclass method UserManager. If I return the instance IdentityUserfrom the method, it works fine, but if I return null(for example, there is no user with this username), I got:
{"Message": "An error occurred.", "ExceptionMessage": "The reference to the object is not installed in the object instance.", "ExceptionType": "System.NullReferenceException", "StackTrace": "at Microsoft.AspNet.Identity .UserValidator`2. ValidateUserName d__4.MoveNext ()
This is my override method.
public Task<MyUser> FindByNameAsync(string userName)
{
return null;
}
I think it does not work in the UserValidatorclass method - ValidateUserNamein the code snippet below.
else
{
var owner = await Manager.FindByNameAsync(user.UserName).WithCurrentCulture();
if (owner != null && !EqualityComparer<TKey>.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, user.UserName));
}
}
FindByNameAsync, ?