Marek M.
Marek M.

Reputation: 3951

Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task'

So, I'm using the below assignment:

Expression<Func<Task>> a = Expression.Lambda<Func<Task>>(() => Task.CompletedTask);

And it results in the error mentioned in the thread subject:

Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task'

I have no idea what I'm doing wrong...

Upvotes: 0

Views: 470

Answers (1)

Guru Stron
Guru Stron

Reputation: 141690

Try removing the Expression.Lambda, compiler should be able to figure out the conversions itself:

Expression<Func<Task>> a = () => Task.CompletedTask;

Upvotes: 2

Related Questions