Some code to replicate the problem:
using System; public abstract class Response { } public abstract class Request<T> where T : Response { } public class LoginResponse : Response { } public class LoginRequest : Request<LoginResponse> { } public class Program { static void Main(string[] args) { LoginRequest login = new LoginRequest(); Request<Response> castTest = login; Request<LoginResponse> castTest2 = login; } }
As far as I can tell, the LoginRequest class is Request <Response> because it inherits from Request <T> and LoginResponse inherits from Response, so can someone tell me why I get a compiler error?
note: I also tried explicit casting
source share