Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task<bool>' in C# Asp.Net Core

Dung Do Tien Feb 26 2022 52

 I just study about C# 9, I try to learn about async/task. I created CreateUser() method as below. body of this method has no call any other async method:

public Task<bool> CreateUser(User model)
{
    if (model == null) return false;
    return true;
}

 I got a compile error Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task<bool>'.

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0029    Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task<bool>'    
Test.GoogleNotification.Dal    C:\Users\conta\source\repos\Test.GoogleNotification\Test.GoogleNotification.Dal\Users\UserDal.cs    21    Active

I try to return Task<false> but it's not working.

How can I resolve it? Thanks for any suggestions.

Have 1 answer(s) found.
  • B

    BIJIT PAL Feb 26 2022

    I think you misunderstand about Async/Await, You lost async keyword in your function, see code below:

    public async Task<bool> Create(User model)
    {
        if (model == null) return false;
        return true;
    }
    

    I hope this information is helpful for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close