Answers for "embed dll in exe C#"

C#
0

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);
            }
        }
    }
}
Posted by: Guest on August-08-2021

C# Answers by Framework

Browse Popular Code Answers by Language