title: ASP.NET Core MVC main project can't reach Controllers in separate assembly
body: <p>I want to use a separate project to store the Controllers for my test app. Due to how <code>ASP.NET Core</code> is working, you need to  call <code>services.AddMvc().AddApplicationPart</code> with the assembly you want to add.</p>
  
  <p>I use <strong>Visual Studio 2017</strong> (so no more <code>project.json</code> there)</p>
  
  <p>The problem is I can't reach the assembly I want to include! </p>
  
  <p>I added reference there in my project:</p>
  
  <p><a href="https://i.stack.imgur.com/x1WBa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x1WBa.png" alt="enter image description here"></a></p>
  
  <p>Also, I decided to use polyfill for AppDomian like so (to reach assembly I need):</p>
  
  <pre><code> public class AppDomain
      {
          public static AppDomain CurrentDomain { get; private set; }
  
          static AppDomain()
          {
              CurrentDomain = new AppDomain();
          }
  
          public Assembly[] GetAssemblies()
          {
              var assemblies = new List&lt;Assembly&gt;();
              var dependencies = DependencyContext.Default.RuntimeLibraries;
              foreach (var library in dependencies)
              {
                  if (IsCandidateCompilationLibrary(library))
                  {
                      var assembly = Assembly.Load(new AssemblyName(library.Name));
                      assemblies.Add(assembly);
                  }
              }
              return assemblies.ToArray();
          }
  
          private static bool IsCandidateCompilationLibrary(RuntimeLibrary compilationLibrary)
          {
              return compilationLibrary.Name == ("TrainDiary")
                  || compilationLibrary.Dependencies.Any(d =&gt; d.Name.StartsWith("TrainDiary"));
          }
      }
  </code></pre>
  
  <p>But when I used it there wasonly one assembly in the list (only linked to this project itself, not one with Controllers).</p>
  
  <p>Here is my <code>Startup.cs</code>:</p>
  
  <pre><code>public class Startup
      {
  
          public IConfigurationRoot Configuration { get; }
          public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                  .AddEnvironmentVariables();
  
              Configuration = builder.Build();
          }
          // This method gets called by the runtime. Use this method to add services to the container.
          // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
          public void ConfigureServices(IServiceCollection services)
          {
              var assemblies = GetAssemblies(); // I tought I will find there Assmbly I need but no
  
              services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
              services.AddReact();
              services.AddMvc();
              services.AddLogging();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
          {
              loggerFactory.AddConsole();
  
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseReact(config =&gt;
              {
              });
  
              app.UseStaticFiles();
              app.UseMvcWithDefaultRoute();
          }
  
          public List&lt;Assembly&gt; GetAssemblies()
          {
              Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
              List&lt;Assembly&gt; currentAssemblies = new List&lt;Assembly&gt;();
  
              foreach (Assembly assembly in assemblies)
              {
                  if (assembly.GetName().Name.Contains("TrainDiary"))
                  {
                      currentAssemblies.Add(assembly);
                  }
              }
  
              return currentAssemblies;
          }
  
      }
  </code></pre>
  
  <p>How can I get my project to also lookup controllers in the other project? Why couldn't it see it? </p>
  
  <p><strong>UPD</strong></p>
  
  <p>Tried to make directly like in this <a href="https://stackoverflow.com/questions/37725934/asp-net-core-mvc-controllers-in-separate-assembly">exapmle</a> here.</p>
  
  <p>So my code started looks like that:</p>
  
  <pre><code>var controllersAssembly = Assembly.Load(new AssemblyName("TrainDiary.Controllers")); 
  services.AddMvc()
          .AddApplicationPart(controllersAssembly)
          .AddControllersAsServices();
  </code></pre>
  
  <p>And it succeed to get the assembly:</p>
  
  <p><a href="https://i.stack.imgur.com/C3dZX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C3dZX.png" alt="enter image description here"></a></p>
  
  <p>But when I try to call Controller function - it fails!</p>
  
  <p>Controller code:</p>
  
  <pre><code>[Route("Login")]
      public class LoginController: Controller
      {
          [Route("Login/Test")]
          public void Test(string name, string password)
          {
              string username = name;
              string pass = password;
          }
      }
  </code></pre>
  
  <p>Requests:</p>
  
  <p><a href="https://i.stack.imgur.com/PUJOu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PUJOu.png" alt="enter image description here"></a></p>
  
  <p><strong>UPD2</strong>:</p>
  
  <p>For some reason remove <code>Routes</code> helped:</p>
  
  <pre><code>public class LoginController: Controller
      {
          public void Test(string name, string password)
          {
              string username = name;
              string pass = password;
          }
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lIl0R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lIl0R.png" alt="enter image description here"></a></p>