title: Howto load assemby at runtime before AssemblyResolve event?
body: <p>Actually i tried to implement some kind of 'statically linked' assemblies, within my solution. So i tried the following:</p>
  
  <ul>
  <li>Adding a reference to my assembly with CopyLocal = false</li>
  <li>Adding the .dll file itself to my solution with 'Add as link'</li>
  <li>Adding the .dll file itself to my resources with 'Add Resource' - 'Add Existing File'</li>
  <li>Adding some type out of my assembly into Form1 as <code>private MyObject temp = new MyObject();</code></li>
  </ul>
  
  <p>After these steps i got the FileNotFoundException as expected. So let's try to load the assembly within the AssemblyResolveEvent with this quick hack</p>
  
  <pre><code>AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =&gt;
      {
          Assembly MyAssembly = AppDomain.CurrentDomain.Load(Properties.Resources.ExternalAssembly);
          return MyAssembly;
      };
  </code></pre>
  
  <p>So this works! I'm able to load my assembly from a resource file within a AssemblyResolveEvent. But this event only happens, if it couldn't find my assembly anywhere else. But how can i get my assembly be loaded <strong>before</strong> .Net tries to search the different places??</p>
  
  <p>Due to the facts from <a href="http://msdn.microsoft.com/en-us/library/aa98tba8.aspx" rel="noreferrer">Checking for Previously Referenced Assemblies</a> i thought it would be possible to load the assembly beforehand into the domain and this would be taken.</p>
  
  <p>I tried this within program.cs by using the following Main() method</p>
  
  <pre><code>static void Main()
  {
      LoadMyAssemblies();
      AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =&gt; LoadMyAssemblies();
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
  }
  
  private static Assembly LoadMyAssemblies()
  {
      Assembly result = AppDomain.CurrentDomain.Load(Properties.Resources.MyStaticAssembly);
      return result;
  }
  </code></pre>
  
  <p>But it still runs into the ResolveEventHandler. And far more better, if i load the assembly again and take a look into <strong>AppDomain.CurrentDomain.GetAssemblies()</strong> i can see that my assembly is loaded twice!!</p>
  
  <p>So any idea why my loaded assembly won't be taken into account when it is loaded before the AssemblyResolve event?? With help of the debugger i also returned a null when the call came from AssemblyResolve, but in this case i got a FileNotFoundException as at the beginning.</p>