title: C# How to cast a generic type to interface it implements
body: <p>This might be a silly question but I couldn't find a solution for it.</p>
  
  <p>I have this structure (simplified for brevity): </p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Test
  {
      public interface IEntity
      { }
  
      public class BaseEntity : IEntity 
      { }
  
      public class OneEntity : BaseEntity
      { }
  
      public class Configuration&lt;T&gt; where T : IEntity 
      {
  
      }
  
      public class Service 
      {
          public Dictionary&lt;string, Configuration&lt;IEntity&gt;&gt; Configurations = new Dictionary&lt;string, Configuration&lt;IEntity&gt;&gt;();
  
          public void RegisterConfiguration(string name, Configuration&lt;T&gt; configuration) where T : IEntity
          {
              if(Configurations.ContainsKey(name))
                  return;
  
              Configurations.Add(name, configuration); //Error: Unable to convert Configuration&lt;T&gt; to Configuration&lt;IEntity&gt;
          }
      }
  }
  </code></pre>
  
  <p>I guess I cannot convert a generic type to an interface, but how can I achieve this? I could write <code>RegisterConfiguration</code> as:<br>
  <code>public void RegisterConfiguration(string name, Configuration&lt;IEntity&gt; configuration)</code>, but then it would fail when I call it with one of my entities (even if they all implement <code>IEntity</code>).  </p>
  
  <p>There must be something I did not understand properly with generics but I can't figure out what.</p>