title: C# Exception during loading DLL's. Can't find solution
body: <p>I have a problem, while loading <code>DLL</code> at runtime in <code>C#</code>.</p>
  
  <p>Following code:</p>
  
  <pre><code>foreach (var f in Directory.EnumerateFiles(startFolder, "*.dll",            SearchOption.AllDirectories))
  {
     try
     {
         var assembly = Assembly.LoadFrom(f);
         var types = assembly.GetTypes(); //exception raised here
  
         foreach (var type in types)
         {
              if (type.GetInterface("IPlayerFactory") != null)
                   instances.Add((IPlayerFactory)Activator.CreateInstance(type));
         }
         assembly = null;
      }
      catch (ReflectionTypeLoadException ex) { /* later, keep reading  */}
  </code></pre>
  
  <p>So exception says: </p>
  
  <pre><code>An exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in
  mscorlib.dll but was not handled in user code
  
  Additional information: Unable to load one or more of the requested types. Retrieve the    
  LoaderExceptions property for more information.
  </code></pre>
  
  <p>I searched stack a little bit and found this <code>catch</code> to look for more information (source: <a href="https://stackoverflow.com/a/8824250/1850043">here</a>)</p>
  
  <p>catch block:</p>
  
  <pre><code>catch (ReflectionTypeLoadException ex)
  {
       StringBuilder sb = new StringBuilder();
       foreach (Exception exSub in ex.LoaderExceptions)
       {
            sb.AppendLine(exSub.Message);
            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
            if (exFileNotFound != null)
            {
                if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                {
                    sb.AppendLine("Fusion Log:");
                    sb.AppendLine(exFileNotFound.FusionLog);
                }
            }
                      sb.AppendLine();
        }
        string errorMessage = sb.ToString();
        //Display or log the error based on your application.
        Console.WriteLine(sb);
   }
  </code></pre>
  
  <p>So i managed to extract:</p>
  
  <pre><code>'Battleships.Desktop.vshost.exe' (CLR v4.0.30319: Battleships.Desktop.vshost.exe):
   Loaded 'C:\SomePath\some_dll.dll'. Cannot find
   or open the PDB file.
   A first chance exception of type 'System.Reflection.ReflectionTypeLoadException'  
   occurred in mscorlib.dll
  </code></pre>
  
  <p>I tried some solutions but nothing works.
  Any fresh ideas?</p>