Task/Task<T>
should not return null
CS-R1006A non-async method with a return type of either Task
or Task<T>
should never return null
. Doing so may result in a NullReferenceException
at runtime. Therefore, it is suggested that you either modify your method's logic or use Task.FromResult<T>(null)
.
public Task<object> GetDataFromServer(string endpoint)
{
if (/* ... */)
{
return null;
}
// ...
}
public Task<object> GetDataFromServer(string endpoint)
{
if (/* ... */)
{
return Task.FromResult<object>(null);
}
// ...
}