title: C# - Getting all assemblies through reflection and their types
body: <p>What I am trying to achieve is get all assemblies from solution with reflection and then their types, so I can have them inside collection <code>Type[]</code> using .NET Core 2.0.</p>
  
  <p>What I can use is</p>
  
  <ul>
  <li><code>AppDomain.CurrentDomain.GetAssemblies();</code> - the problem is that this will get all referenced and used assemblies. In my case I want to get all assemblies that are referenced, but not necessary used. So the problem is that JIT compilation is removing references for projects that are not used, so in that case this wouldn't work.</li>
  <li>Other option is to get location of DLLs using <code>Assembly.GetExecutingAssembly().Location</code> and then load all assemblies. The problem here is that, when latter I want to use <code>.GetTypes()</code> this throw exception from type <code>System.Reflection.ReflectionTypeLoadException</code> and then loader exception I have <code>System.IO.FileNotFoundException: Could not load file or assembly Microsoft.EntityFrameworkCore</code>. The issue, is that it's trying to use libraries, which cannot find, apperantly loading DLLs using <code>Assembly.LoadFrom(dll)</code> doesn't seem to load dependencies (libraries) as well.</li>
  </ul>
  
  <p>What I found is <a href="https://msdn.microsoft.com/en-us/library/system.web.compilation.buildmanager.getreferencedassemblies(v=vs.110).aspx" rel="noreferrer">BuildManager.GetReferencedAssemblies</a>, from what I read so far, it's saying that this could work and it's getting all references, even if they're not used, so I also found it in MsBuild library, but doesn't contains that method, so I might be referencing wrong package.</p>
  
  <p>I am open for any suggestions, how I can load all solution assemblies and their types from .NET Core 2.0 project.</p>
  
  <p>Thanks in advance!</p>