title: Why does the variance of a class type parameter have to match the variance of its methods' return/argument type parameters?
body: <p>The following raises complaints:</p>
  
  <pre><code>interface IInvariant&lt;TInv&gt; {}
  interface ICovariant&lt;out TCov&gt; {
      IInvariant&lt;TCov&gt; M(); // The covariant type parameter `TCov'
                            // must be invariantly valid on
                            // `ICovariant&lt;TCov&gt;.M()'
  }
  interface IContravariant&lt;in TCon&gt; {
      void M(IInvariant&lt;TCon&gt; v); // The contravariant type parameter
                                  // `TCon' must be invariantly valid
                                  // on `IContravariant&lt;TCon&gt;.M()'
  }
  </code></pre>
  
  <p>but I can't imagine where this wouldn't be type-safe. (snip*) Is this the reason why this is disallowed, or is there some other case which violates type safety which I'm not aware of?</p>
  
  <hr>
  
  <p>* My initial thoughts were admittedly convoluted, but despite this, the responses are very thorough, and <a href="https://stackoverflow.com/a/37281836/3925507">@Theodoros Chatzigiannakis</a> even dissected my initial assumptions with impressive accuracy. </p>
  
  <p>Alongside a good slap from retrospect, I realize that I had falsely assumed that the type signature of <code>ICovariant::M</code> remains a <code>Func&lt;IInvariant&lt;Derived&gt;&gt;</code> when its <code>ICovariant&lt;Derived&gt;</code> is assigned to a <code>ICovariant&lt;Base&gt;</code>. Then, assigning that <code>M</code> to <code>Func&lt;IInvariant&lt;Base&gt;&gt;</code> would <em>look</em> fine coming from an <code>ICovariant&lt;Base&gt;</code>, but would of course be illegal. Why not just ban this last, obviously-illegal cast? (so I thought)</p>
  
  <p>I feel this false and tangential guess detracts from the question, as <a href="https://stackoverflow.com/a/37285343/3925507">Eric Lippert</a> also points out, but for historical purposes, the snipped part:</p>
  
  <blockquote>
    <p>The most intuitive explanation to me is that, taking <code>ICovariant</code> as an example, the covariant <code>TCov</code> implies that the method <code>IInvariant&lt;TCov&gt; M()</code> could be cast to some <code>IInvariant&lt;TSuper&gt; M()</code> where <code>TSuper super TCov</code>, which violates the invariance of <code>TInv</code> in <code>IInvariant</code>. However, this implication doesn't seem necessary: the invariance of <code>IInvariant</code> on <code>TInv</code> could easily be enforced by disallowing the cast of <code>M</code>. </p>
  </blockquote>