None of the Generic methods properly support contravarience


Attempting to pass in an enumeration instance assigned to a variable of type System.Enum will cause an ArgumentException to be thrown (in this case, a contravarience issue).


rmiesen wrote Aug 28, 2010 at 9:26 PM

This bug cannot be fixed at this time because C# 4.0 only allows the use of the covarience and contravarience constructs inside interface definitions. I have sent this issue upstream to Microsoft. You can follow the progress of this issue at https://connect.microsoft.com/VisualStudio/feedback/details/590560/support-for-the-covarience-and-contravarience-constructs-in-classes-and-methods

Leaving open.

rmiesen wrote Aug 28, 2010 at 9:28 PM

As a work-around, I have added Code Contracts to all methods that check to make sure that all parameters of type TEnum are a subclass of System.Enum. This makes it impossible to trip on the contravarience issue.

wrote Aug 29, 2010 at 3:26 AM

wrote Feb 2, 2013 at 2:19 AM