title: Why am I getting "The type parameter must be invariantly valid..." error?
body: <p>I'll attempt to shorten this code example:</p>
  
  <pre><code>public interface IThing
  {
      //...  Stuff
  }
  
  public class Thing1 : IThing
  {  
  }
  
  public class Thing2 : IThing
  {  
  }
  
  public interface IThingView&lt;out T&gt;
  {
      ICollection&lt;T&gt; ViewAll();
  }
  
  public class ThingView&lt;T&gt; : IThingView&lt;T&gt;
  {
      ICollection&lt;T&gt; ViewAll() { return new List&lt;T&gt;(); }  //  There's a big operation here
  }
  
  public interface IThingViewerFactory
  {
      public IThingView&lt;IThing&gt; Build(string Which);
  }
  
  public class ThingViewerFactory
  {
      public IThingView&lt;IThing&gt; Build(string Which)
      {
          if(Which.Equals("Thing1") { return new (IThingView&lt;IThing&gt;)new ThingViewer&lt;Thing1&gt;();}
          else { return new (IThingView&lt;IThing&gt;)new ThingViewer&lt;Thing2&gt;();}
      }
  }
  </code></pre>
  
  <p>That's a rough idea of what I'm doing.  I have a number of Thing classes that require a viewer, which will follow a comon interface.  I'd like a factory to generate these by me passing in a string with the name.  I keep getting a compiler error complaining:</p>
  
  <p>Invalid variance: The type parameter 'T' must be invariantly valid on 'IThingView.ViewAll()'. 'T' is covariant.</p>
  
  <p>I realize even if I get this to work, I'll have to do some casting afterwards... I'm fine with that.  And I realize this approach is more than likely not necessary.  At this point this has become more of a pride/curiosity issue.</p>
  
  <p>Thanks!</p>