title: How do I use AppDomain.CreateDomain with AssemblyResolve?
body: <p>I want to load my assemblies from WCF by using memory. Everything is working good WHEN:</p>
  
  <pre><code>AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
  Assembly[] assBefore = AppDomain.CurrentDomain.GetAssemblies();
  foreach (byte[] binary in deCompressBinaries)
      loadedAssembly = AppDomain.CurrentDomain.Load(binary);
  </code></pre>
  
  <p>But I want to use AppDomain.CreateDomain, not the current domain:</p>
  
  <pre><code>protected void LoadApplication()
  {
      this.ApplicationHost = AppDomain.CreateDomain("TestService", null, new AppDomainSetup
      {
          ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
      });
  
      ApplicationHost.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve);
      foreach (AssemblyName asmbly in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies())
      {
          ApplicationHost.Load(asmbly);
      }
      List&lt;byte[]&gt; deCompressBinaries = new List&lt;byte[]&gt;();
      foreach (var item in AppPackage.Item.AssemblyPackage)
          deCompressBinaries.Add(item.Buffer);
      var decompressvalues =  DeCompress(deCompressBinaries);
      deCompressBinaries.Clear();
      deCompressBinaries = decompressvalues.ToList();
  
      foreach (byte[] binary in deCompressBinaries)
          ApplicationHost.Load(binary);
  
      Assembly[] assAfter = AppDomain.CurrentDomain.GetAssemblies();
  }
  
  Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
  {
      return Assembly.Load(args.Name);
  }
  </code></pre>
  
  <p>I have two class libraries, ClassLibrary1 and ClassLibrary2 using the below:</p>
  
  <pre><code>namespace ClassLibrary2
  {
      public class Class1 : MarshalByRefObject
      {
          public Class1()
          {
  
          }
  
          public int GetSum(int a , int b)
          {
              try
              {
                  ClassLibrary1.Class1 ctx = new ClassLibrary1.Class1();
                  return ctx.Sum(a, b);
              }
              catch
              {
                  return -1;
              }
          }
  
          public int GetMultiply(int a, int b)
          {
              return a * b;
          }
      }
  }
  </code></pre>
  
  <p>Classlibrary2 depends on ClassLibrary1. So I am using assemblyresolver. But I get an error on <strong>ApplicationHost.Load(binary);</strong>:</p>
  
  <blockquote>
    <p>Error: <strong>Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.</strong></p>
  </blockquote>
  
  <p>Also it is NOT FIRING ASSEMBLYRESOLVER. My cursor is not going to  the Assemblyresolver method. How do I use AppDomain.CreateDomain with the resolve method?</p>