title: ILMerge alternative, how to embed application’s dependent DLLs inside an EXE file?
body: <p><a href="http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx" rel="nofollow">As stated here</a> im trying to embed the dlls in the exe application in order to just distribute one exe, but when i try to run my application on a xp machine with full .NET 4 installed it just crashes with no error, im placing the following code on the main method</p>
  
  <pre><code>[STAThread]
          static void Main()
          {
              AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =&gt;
              {
                  String resourceName = "AssemblyLoadingAndReflection." + new AssemblyName(args.Name).Name + ".dll";
  
                  using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                  {
                      Byte[] assemblyData = new Byte[stream.Length];
                      stream.Read(assemblyData, 0, assemblyData.Length);
                      return Assembly.Load(assemblyData);
                  }
              };
  
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new frmrPrincipal());
          }
  </code></pre>
  
  <p>i have a folder named dlls where im placing</p>
  
  <pre><code>Functions.Shared.dll
  Alex.UI.dll
  Alex.Controls.dll
  </code></pre>
  
  <p>and im setting its Build Action to "Embedded Resource".</p>
  
  <p>if i remove that piece of code and set the dlls to be included by click once installer it works fine. btw im Using .NET Framework 4 Full profile and VS2010 SP1</p>