That's expected behavior. .NET 4.0's version of
IComparer<>
is contravariant, see below:
public interface IComparer<in T>
In .NET 3.5 there was no notion of contravariance. So in 3.5 you would need a cast as follows:
Class2<T, IComparer<T>> returnVal = new Class2<T, IComparer<T>>(
(IComparer<T>)new ComparingClass());
For more info, see a blog entry I did some time ago:
C# 4.0 and variant generic interfaces[
^]