Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have no idea what I’m doing wrong…

>Solution :

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

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading