Cannot implicitly convert type ‘bool’ to ‘system.threading.tasks.task bool’

You need to be specific whether you want this operation happen asynchronously or not.

As an example for Async Operation :

public async Task<bool> login(string usn, string pwd)
{
    DataClasses1DataContext auth = new DataClasses1DataContext();
    var message = await (from p in auth.Users
                  where p.usrName == usn && p.usrPass == pwd
                  select p);
    if (message.Count() > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

If you don’t need it to be an Async operation, try this:

public bool login(string usn, string pwd)
{
    DataClasses1DataContext auth = new DataClasses1DataContext();
    var message = from p in auth.Users
                  where p.usrName == usn && p.usrPass == pwd
                  select p;
    if (message.Count() > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

Note:
async and await are compatible with .net 4.5 and C# 5.0 and more

Leave a Comment

error code: 521