Why is this an issue?
Returning null
from a non-async
Task
/Task<T>
method will cause a
NullReferenceException
at runtime. This problem can be avoided by returning Task.FromResult<T>(null)
instead.
Noncompliant code example
public Task<object> GetFooAsync()
{
return null; // Noncompliant
}
Compliant solution
public Task<object> GetFooAsync()
{
return Task.FromResult<object>(null);
}