title: Add assembly controller and view at runtime after start project ASP.NET Core 3.1
body: <p>I want load assemblies at runtime, not Startup ( after start application ).
  For this, I searched many solutions over the Internet and StackOverflow.
  I found this answer at <a href="https://stackoverflow.com/questions/46156649/asp-net-core-register-controller-at-runtime/47629660#47629660">ASP.Net Core register Controller at runtime</a></p>
  <p>cnxiaoby said: Create ActionDescriptor and register that in a startup.
  Then anywhere you can use <code>_partManager.ApplicationParts.Add(assembly);</code>
  Everything is fine, but I can just add Controller classes at runtime, If I want to add Razor views at runtime after start application, I get <a href="https://i.stack.imgur.com/oh6hj.png" rel="nofollow noreferrer">&quot;Not Found View Index&quot;</a></p>
  <p>Add views by this code:</p>
  <pre><code>var newView = AssemblyLoadContext.Default.LoadFromAssemblyPath(data.FullName);
  var viewAssembly = new CompiledRazorAssemblyPart(newView);
  _partManager.ApplicationParts.Add(viewAssembly);
  </code></pre>
  <p>Add Controllers by this code:</p>
  <pre><code>var targetAssembly = new AssemblyPart(assembly);
  _partManager.ApplicationParts.Add(targetAssembly);
  </code></pre>
  <p>After that, I set Custom Action Descriptor to this:</p>
  <pre><code>MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
  </code></pre>
  <p><strong>Edit:</strong>
  That code was in HomeController.cs and SampleAction
  If I put all codes inside HomeController.cs and Index&quot;Action&quot;, Everything is fine.
  If move code to other actions ( After application run and start run other action ), Code not work and I see that error.</p>
  <ol>
  <li>What did I forget?</li>
  <li>Why Code in First Action of project is fine, but not for others?</li>
  <li>What is the difference between the first action and the rest?</li>
  </ol>