title: ASP.NET MVC BuildManager.GetAssemblies()
body: <p>I'm working in an ASP.NET MVC 4 application, and on app start up I'm looking using BuildManager to get all referenced assemblies.I'm looking through all types in the application to find a few that I want (it's dynamic so I don't know what types I need until start up). </p>
  
  <p>Essentially my code looks like this:</p>
  
  <pre><code>var allTypes = BuildManager.GetReferencedAssemblies()
                    .Cast&lt;Assembly&gt;()
                    .SelectMany(a =&gt; a.GetTypes());
  </code></pre>
  
  <p>I'm calling this on app startup but also at the beginning of each new request in order to dynamically find types.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Since ASP.NET doesn't load assemblies until they're needed, by calling <code>BuildManager.GetReferencedAssemblies()</code> am I loading ALL assemblies before they're needed and causing a performance issue?</li>
  <li>Is iterating through all types a bad idea for each request? I could cache the types but ASP.NET has the option of loading assemblies dynamically after I've cached them, right? If so I may miss some types which are indeed there.</li>
  </ol>
  
  <p>Thanks!</p>