title: Why can't you cast from IList<IParent> to IList<IChild> where IChild implements IParent
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1457265/ilisttype-to-ilistbasetype">IList&lt;Type&gt; to IList&lt;BaseType&gt;</a>  </p>
  </blockquote>
  
  <p>I am programming in C# using .NET 2.0 and I don't understand why the cast below results in a null reference.</p>
  
  <p>If you have an IList&lt;IChild&gt;, why can't you cast it to an IList&lt;IParent&gt; where IChild implements IParent.</p>
  
  <pre><code>using System.Collections.Generic;
  
  namespace InterfaceTest
  {
      public interface IParent
      {
      }
  
      public interface IChild : IParent
      {
      }
  
      public abstract class Parent : IParent
      {
      }
  
      public sealed class Child : Parent, IChild
      {
      }
  
      public sealed class Container
      {
          public IList&lt;IChild&gt; ChildInterfaceList
          {
              get;
              set;
          }
  
          public Container()
          {
              ChildInterfaceList = new List&lt;IChild&gt;();
          }
      }
  
      class Program
      {
      static void Main(string[] args)
      {
              Container container = new Container();
  
              var childInterfaceList = container.ChildInterfaceList;
  
              System.Diagnostics.Debug.Assert(childInterfaceList != null);
  
              var parentInterfaceList = container.ChildInterfaceList as IList&lt;IParent&gt;;
  
              //I don't expect parentInterfaceList to be null, but it is
              System.Diagnostics.Debug.Assert(parentInterfaceList != null);
          }
      }
  }
  </code></pre>