In .NET 6, I have an interface and a type:
internal interface IProvider
{
}
public class TProvider : IProvider
{
}
I want to use a covariant T in another interface like this:
internal interface IFactory<out T>
{
Task<T> Create();
}
But on the line Task<T> Create(), I am getting an error:
The type parameter 'T' must be invariantly valid on 'IFactory.Create()'. 'T' is covariant
If I change the method call to a synchronous version -- T Create() -- it compiles.
Is there a way to keep T as covariant and return Task<T> as part of an asynchronous method signature?