title: cast to base-type not supported for generic method
body: <p>I have an interface <code>IGenericOrder</code> as follows:</p>
  
  <pre><code>using System;
  using System.Linq.Expressions;
  
  namespace MyNamespace
  {
      interface IGenericOrder&lt;T&gt; where T : new()
      {
          Func&lt;T, int&gt; GetStatement(string name);
      }
  
  
      public class GenericOrder&lt;T&gt; : IGenericOrder&lt;T&gt; where T : new()
      {
          public Func&lt;T, int&gt; GetStatement(string name)
          {
              return (T) =&gt; 4;
          }    
      }
  }
  </code></pre>
  
  <p>Now when I create an instance of that class and cast it back to <code>IGenericOrder&lt;object&gt;</code> </p>
  
  <pre><code>var sorter = (IGenericOrder&lt;object&gt;) new GenericOrder&lt;Foo&gt;();
  </code></pre>
  
  <p>I get Exception:</p>
  
  <blockquote>
    <p>InvalidCastException: The instance of type <code>GenericOrder&lt;Foo&gt;</code> cannot be cast to <code>IGenericOrder&lt;object&gt;</code></p>
  </blockquote>
  
  <p>Which seems clear as the Interface <code>IGenericOrder</code> is not covariant. However if I make the interface covariant (<code>interface  IGenericOrder&lt;out T&gt;</code>) I get a compiler-error:</p>
  
  <blockquote>
    <p>Invalid variance: The type parameter 'T' must be contravariantly valid on <code>IGenericOrder&lt;T&gt;.GetStatement(string)</code>. 'T' is covariant.</p>
  </blockquote>
  
  <p>As I read from <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx" rel="nofollow">here</a> covariance can only used when</p>
  
  <blockquote>
    <p>[the generic type parameter] is used only as a method return type and is not used as a type of formal method parameters. </p>
  </blockquote>
  
  <p>Does this mean I cannot use co-/contravariance for methods that themselfes return generic instances?</p>
  
  <p>I am using .Net 4.5</p>