The only way is at runtime.
I adapted the answer from the answer, which I posted in the comments.
public class Test<A, B> { static Test() { if (typeof(B) == typeof(A)) { throw new NotSupportedException("Argument B is not supported."); } } }
source share