using System;
namespace hello
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
Now I created another project to execute the .Net assebly of the previous project |
|
using System;
using System.IO;
using System.Reflection;
namespace LoadAssembly
{
class Program
{
static void Main(string[] args)
{
Byte[] bytes = File.ReadAllBytes(@"C:/Users/dzosoft/source/repos/Hello/bin/Debug/Hello.exe");
Assembly assembly = Assembly.Load(bytes);
MethodInfo method = assembly.EntryPoint;
string[] param = new string[] { "hi" };
object[] parameters = new[] { param };
object execute = method.Invoke(null, parameters);
}
}
}
|
|
That will work and print out “hello world!”. This works for DLLs too, change the file to have this instead and build it again. |
|
using System;
using System.IO;
using System.Reflection;
namespace LoadAssembly
{
class Program
{
static void Main(string[] args)
{
Byte[] bytes = File.ReadAllBytes(@"/Users/guru/hello.dll");
Assembly assembly = Assembly.Load(bytes);
MethodInfo method = assembly.EntryPoint;
string[] param = new string[] { "hi" };
object[] parameters = new[] { param };
object execute = method.Invoke(null,parameters);
}
}
}
|