title: C# The is no implicit reference conversion from 'B' to 'A' using Generics
body: <p>I'm with problems to convert from the type derived to base type using Generics.</p>
  
  <p>Class to manage the dictionary:</p>
  
  <pre><code>public class ManagerDictionary&lt;TContext&gt;
  {
      public ManagerDictionary()
      {    
          this.Dictionary = new Dictionary&lt;int, TContext&gt;();
      }
  
      public IDictionary&lt;int, TContext&gt; Dictionary { get; private set; }
  
      public void Register&lt;TSubContext&gt;(int context, TSubContext subContext) where TSubContext : TContext
      {
          this.Dictionary[context] = subContext;
      }
  }
  </code></pre>
  
  <p>Interface of the Process context:</p>
  
  <pre><code>public interface IProcessContext : IContext&lt;ProcessViewModel&gt;
  {
  }
  </code></pre>
  
  <p>My test class:</p>
  
  <pre><code>public class Foo&lt;TViewModelContext&gt; where TViewModelContext : ViewModeBase
  {
      public Foo(IProcessContext processContext)
      {
          // Create de Dictionary Manager.
          this.ManagerDictionary = new ManagerDictionary&lt;IContext&lt;TViewModelContext&gt;&gt;();
  
          // Register the process context on dictionary.
          // The error is occurring here: The is no implicit reference conversion from 'IProcessContext' to 'IContext&lt;TViewModelContext&gt;'
          this.ManagerDictionary.Register((int)ContextType.Process, processContext);
      }
  
      protected ManagerDictionary&lt;IContext&lt;TViewModelContext&gt;&gt; ManagerDictionary { get; set; }
  }
  </code></pre>
  
  <p>When I try register the processContext, the problem occurs:</p>
  
  <blockquote>
    <p>The is no implicit reference conversion from <code>'IProcessContext'</code> to
    <code>IContext&lt;TViewModelContext&gt;</code></p>
  </blockquote>
  
  <p>How can I resolve this problem?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>When I Create a inherited class of the Foo, I can register, but I need register on Foo class too.</p>
  
  <pre><code>public interface IAnotherProcessContext : IContext&lt;ProcessTwoViewModel&gt;
  {
  }
  
  public class InheritedFoo : Foo&lt;ProcessTwoViewModel&gt;
  {
      public InheritedFoo(IAnotherProcessContext anotherProcessContext)
      {
          base.ManagerDictionary.Register((int)ContextType.InheritedProcess, anotherProcessContext);
      }
  }
  </code></pre>