title: How to load an assembly from byte array in compact framework
body: <p>I have legacy clients who use smart scanners with old windows mobile on them. As a result, I'm stuck developing in the compact framework for these smart devices. I am in the process of writing  a class library which will provide a plugin type mechanism for an interface to the scanner hardware. I would like to be able to embed the third party assemblies from the scanner manufacturer as an embedded resource in the plugins DLL. I want to do this to avoid having to reflect over all of those third party DLL's when my plugin system is trying to find implementations of the interface for the plugins. Pretty strait forward. The issue is that with the embedded resource, I can get the bytes for the assembly, but <code>System.Reflection.Assembly.LoadAssembly(byte[])</code> is not available in the compact framework. Only <code>LoadAssembly(AssemblyName)</code> and <code>LoadAssembly(String)</code>. How can I load these assemblies at runtime from an embedded resource?</p>
  
  <p>This is what I have now:</p>
  
  <pre><code>    protected void LoadEmbeddedAssemblies()
      {
          Assembly asm = Assembly.GetCallingAssembly();
          foreach (string resName in asm.GetManifestResourceNames())
          {
              if (resName.EndsWith(".dll"))
              {
                  try
                  {
                      //this is an embedded assembly
                      using (Stream s = asm.GetManifestResourceStream(resName))
                      {
                          if (s.Length &gt; Int32.MaxValue) throw new IOException("The assembly is to large");
                          byte[] bytes = new byte[s.Length];                            
                          s.Read(bytes, 0, Convert.ToInt32(s.Length));
  
                          //Assembly.Load(bytes) &lt;- Compact Framework sucks
                      }
                  }
                  catch (Exception e)
                  {
                      Log(new LogMessageRaisedEventArgs("AScannerBase", "LoadEmbeddedAssemblies", "Exception encountered while loading embedded assembly", e.Message));
                  }
              }
          }
      }
  </code></pre>