title: Covariant object instantiation using reflection
body: <p>It seems that i have found a strange bug in .NET-2.0/unity's .NET-2.0.</p>
  
  <pre><code>public class Test
  {
      public interface ICovariant&lt;out T&gt;
      {
          T GetT();
      }
  
      public class Covariant&lt;T&gt;: ICovariant&lt;T&gt;
      {
          public T GetT()
          {
              throw new NotImplementedException();
          }
      }
  
      public interface IFoo
      {
      }
  
      public class Bar : IFoo
      {
      }
  
      public class CovariantHolder
      {
          public CovariantHolder(ICovariant&lt;IFoo&gt; covariant)
          {
          }
      }
  
      public class CovariantBar: Covariant&lt;Bar&gt;
      {
      }
  
      public static void Main(string[] args)
      {
          ICovariant&lt;IFoo&gt; foo = new Covariant&lt;IFoo&gt;();
          ICovariant&lt;IFoo&gt; foobar = new Covariant&lt;Bar&gt;();
          ICovariant&lt;IFoo&gt; bar = new CovariantBar();
          CovariantBar barbar = new CovariantBar();
  
          new CovariantHolder(foo);     // works
          new CovariantHolder(foobar);  // works
          new CovariantHolder(bar);     // works
          new CovariantHolder(barbar);  // works
  
          Console.WriteLine(typeof(ICovariant&lt;IFoo&gt;).IsAssignableFrom(typeof(Covariant&lt;IFoo&gt;))); // true;
          Console.WriteLine(typeof(ICovariant&lt;IFoo&gt;).IsAssignableFrom(typeof(Covariant&lt;Bar&gt;)));  // true;
          Console.WriteLine(typeof(ICovariant&lt;IFoo&gt;).IsAssignableFrom(typeof(CovariantBar)));    // false! what?;
  
          typeof(CovariantHolder).GetConstructors()[0].Invoke(new object[] {foo});      //works
          typeof(CovariantHolder).GetConstructors()[0].Invoke(new object[] {foobar});   //fails! WHAAT?
          typeof(CovariantHolder).GetConstructors()[0].Invoke(new object[] {bar});      //fails!
          typeof(CovariantHolder).GetConstructors()[0].Invoke(new object[] {barbar});   //fails!
      }
  }
  </code></pre>
  
  <p>AFAIK, unity uses mono 2.0.50727.1433</p>
  
  <p>Is there any way around it? Can I instatniate an object through reflection using covariant argument?</p>
  
  <p><strong>UPD</strong>:
  error code:
  <code>InvalidCastException: Value is not a convertible object: Test+Covariant``1[GameInstaller+Bar] to Test+ICovariant``1[[Test+IFoo, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]</code></p>