Reputation: 18251
I have async method:
public async Task CreateAndWriteAsyncToFile()
{
using (FileStream stream = new FileStream("test.dat", FileMode.Create,FileAccess.Write, FileShare.None, 4096, true))
{
byte[] data = new byte[100000];
new Random().NextBytes(data);
await stream.WriteAsync(data, 0, data.Length);
}
}
Compiler complains :
The return type of async method must be void, Task or Task not all code paths returns value.
How to solve this method
Upvotes: 0
Views: 161
Reputation: 118
Just to be sure, check if you did import the System.Threading.Tasks namespace. If you accidentally created a Task class (Visual Studio will suggest you to create a class if it doesn't exists) be sure to remove it.
Upvotes: 1
Reputation: 56489
There's nothing wrong with your code, the issue seems that you have another Task
type defined somewhere in your project. change the method signature to:
public async System.Threading.Tasks.Task CreateAndWriteAsyncToFile(){ ... }
Upvotes: 7