title: Referenced Assembly Not Found - How to get all DLLs included in solution
body: <p>I'm running a WCF application <code>CoreApplication</code> whose VS project has a reference to <code>AncillaryProject</code>. <code>CoreApplication</code> uses a class <code>Provider</code> from <code>AncillaryProject</code>; however, it is never explicitly referenced - it's invoked via Reflection.</p>
  
  <p>My problem is that <em>sometimes</em> <code>CoreApplication</code> fails to find <code>Provider</code> because <code>AncillaryProject</code> does not come up in the call to <code>GetAssemblies()</code>. Sometimes it works fine, but sometimes (I'm guessing it may be after a JIT) it fails.</p>
  
  <p>Here's my original code:</p>
  
  <pre><code>var providers = from d in AppDomain.CurrentDomain.GetAssemblies()
                  from c in d.GetTypes()
                  where typeof(BaseProvider).IsAssignableFrom(c)
                  select c;
  </code></pre>
  
  <p>After looking at <a href="https://stackoverflow.com/questions/2384592/c-net-is-there-a-way-to-force-all-referenced-assemblies-to-be-loaded-into-the">this question</a>, I tried using <code>GetReferencedAssemblies()</code>:</p>
  
  <pre><code>var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
  foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
  {
      allAssemblies = allAssemblies.Union(
                            a.GetReferencedAssemblies()
                             .Select(b =&gt; System.Reflection.Assembly.Load(b)));
  }
  var providers = from d in allAssemblies
                  from c in d.GetTypes()
                  where typeof(BaseProvider).IsAssignableFrom(c)
                  select c;
  </code></pre>
  
  <p>I realize that the question I referenced solves the problem through dynamically loading all dll files in the bin directory, but that doesn't sound particularly good to me. <strong>Is there a better way to do this</strong>, or is .NET simply not loading the other Assemblies in at all? <strong>How does this work under the hood</strong>, and is there anything I can do about it?</p>