title: Unity Container Registration with Names are not working while without name works fine
body: <p>I know this sounds stupid. I'll provide some pieces of code and will try to explain as much.</p>
  
  <h3>Implementation #1 - Without name</h3>
  
  <pre><code>   Container = new UnityContainer();
  
      Container.RegisterType&lt;IFirstInterface, FirstImplementation&gt;();
  
      Container.RegisterType&lt;IDifferentAssemblyInterface, DifferentAssemblyImplementation&gt;();
      Container.RegisterType&lt;ISameAssemblyInterface, SameAssemblyImplementation&gt;();
  </code></pre>
  
  <h3>Implementation #2 - With name</h3>
  
  <pre><code>const string configurationName = "simpleOption";
  
  Container = new UnityContainer();
  
          Container.RegisterType&lt;IFirstInterface, FirstImplementation&gt;(configurationName);
  
          Container.RegisterType&lt;IDifferentAssemblyInterface, DifferentAssemblyImplementation&gt;(configurationName);
          Container.RegisterType&lt;ISameAssemblyInterface, SameAssemblyImplementation&gt;(configurationName);
  </code></pre>
  
  <h3>Observations</h3>
  
  <p>Implementation #1 works just fine. I used the immediate window and everything resolves.</p>
  
  <p>With implementation #2 I used immediate window and everything from the same assembly resolves</p>
  
  <p>Implementation #2 immediate window is not able to resolve exactly the IDifferentAssemblyInterface is not able to resolve</p>
  
  <p>I opened up the Registrations constructor and all the dependencies are </p>
  
  <h3>Questions</h3>
  
  <ol>
  <li>Am I using named registration correctly?</li>
  <li>Is passing the name as simple as that? Just pass a string while registering and the same string during resolve should work.</li>
  <li>How do I debug/resolve this?</li>
  </ol>
  
  <h3>Sample Code</h3>
  
  <p>Program.cs</p>
  
  <pre><code>  static IUnityContainer Container;
      static void Main(string[] args)
      {
          // Arrange
          Container = new UnityContainer();
          Container.AddExtension(new Diagnostic());
  
  
          Container.RegisterType&lt;IMessageReader, ConsoleMessageReader&gt;("Local");
          Container.RegisterType&lt;IMessageWriter, ConsoleMessageWriter&gt;("Local");
          Container.RegisterType&lt;Startup, Startup&gt;("Local");
  
          Startup startup = Container.Resolve&lt;Startup&gt;("Local");
  
          // Act
          startup.Run();
      }
  </code></pre>
  
  <p>Startup.cs</p>
  
  <pre><code>  public class Startup
      {
          IMessageReader _reader;
          IMessageWriter _writer;
  
          public Startup(IMessageReader reader, IMessageWriter writer)
          {
              _reader = reader;
              _writer = writer;
  
          }
          public void Run()
          {
              _writer.WriteMessage(_reader.ReadMessage());
          }
      }
  </code></pre>
  
  <p>Message ReaderWriter</p>
  
  <pre><code>public interface IMessageReader
  {
      string ReadMessage();
  }
  public class ConsoleMessageReader : IMessageReader
  {
      public string ReadMessage()
      {
          return "Hello, DI";
      }
  }
  
  public interface IMessageWriter
  {
      void WriteMessage(string message);
  }
  public class ConsoleMessageWriter : IMessageWriter
  {
      public void WriteMessage(string message)
      {
          Console.WriteLine("{0}", message);
      }
  }
  </code></pre>
  
  <h3>Error Message</h3>
  
  <pre><code>Unhandled Exception: Unity.ResolutionFailedException: The current type, HelloDIApp.ConsoleClient.IMessageReader, is an interface and cannot be constructed. Are you missing a type mapping?
  _____________________________________________________
  Exception occurred while:
  
  ·resolving type:  'IMessageReader'
    for parameter:  'reader'
    on constructor:  Startup(IMessageReader reader, IMessageWriter writer)
     resolving type:  'Startup' registered with name: 'Local'
   ---&gt; System.InvalidOperationException: The current type, HelloDIApp.ConsoleClient.IMessageReader, is an interface and cannot be constructed. Are you missing a type mapping? ---&gt; Unity.Exceptions.InvalidRegistrationException: Exception of type 'Unity.Exceptions.InvalidRegistrationException' was thrown.
     --- End of inner exception stack trace ---
     at Unity.Processors.ConstructorDiagnostic.&lt;&gt;c.&lt;GetResolver&gt;b__11_0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.UnityContainer.&lt;&gt;c__DisplayClass96_0.&lt;OptimizingFactory&gt;b__0(BuilderContext&amp; c)
     at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext&amp; context)
     at Unity.UnityContainer.ContextValidatingPlan(BuilderStrategy[] chain, BuilderContext&amp; context)
     at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
     at Unity.Builder.BuilderContext.Resolve(Type type, String name)
     at Unity.Builder.BuilderContext.Resolve(ParameterInfo parameter, Object value)
     at Unity.Processors.ParametersProcessor`1.&lt;&gt;c__DisplayClass1_0.&lt;CreateDiagnosticParameterResolvers&gt;b__0(BuilderContext&amp; context)
     at Unity.Processors.ConstructorDiagnostic.&lt;&gt;c__DisplayClass12_0.&lt;GetResolverDelegate&gt;b__0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.Processors.MemberProcessor`2.&lt;&gt;c__DisplayClass8_0.&lt;GetResolver&gt;b__0(BuilderContext&amp; c)
     at Unity.UnityContainer.&lt;&gt;c__DisplayClass96_0.&lt;OptimizingFactory&gt;b__0(BuilderContext&amp; c)
     at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext&amp; context)
     at Unity.UnityContainer.ExecuteValidatingPlan(BuilderContext&amp; context)
     --- End of inner exception stack trace ---
     at Unity.UnityContainer.ExecuteValidatingPlan(BuilderContext&amp; context)
     at Unity.UnityContainer.Unity.IUnityContainer.Resolve(Type type, String name, ResolverOverride[] overrides)
     at Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, String name, ResolverOverride[] overrides)
     at HelloDIApp.ConsoleClient.Program.Main(String[] args) in C:\Code\HelloDI\HelloDIApp\HelloDIApp.ConsoleClient\Program.cs:line 18
  </code></pre>
  
  <h3>Working Code</h3>
  
  <p>When I don't use names it works just fine.</p>
  
  <pre><code>static void Main(string[] args)
  {
      // Arrange
      Container = new UnityContainer();
      Container.AddExtension(new Diagnostic());
  
      Container.RegisterType&lt;IMessageReader, ConsoleMessageReader&gt;();
      Container.RegisterType&lt;IMessageWriter, ConsoleMessageWriter&gt;();
      Container.RegisterType&lt;Startup, Startup&gt;();
  
      Startup startup = Container.Resolve&lt;Startup&gt;();
  
      // Act
      startup.Run();
  }
  </code></pre>