embed dll in exe C#
using System;
using System.IO;
using System.Reflection;
namespace MyApp
{
static class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(LoadExternalASM);
}
private static Assembly LoadExternalASM(object sender, ResolveEventArgs e)
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyApp.ExternalDLL.dll"))
{
byte[] dlldata = new byte[s.Length];
s.Read(dlldata, 0, dlldata.Length);
return Assembly.Load(dlldata);
}
}
}
}