I am developing an application, I want to load exe file (which is an embedded Resource file in my application) and then load Assembly from that byte[] array and run it in main memory. I have followed this Stack Overflow Question and this Article But I am getting this error.
Error: could not load file or assembly
Here is my code:
try
{
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
Assembly a = Assembly.Load(bin);
MethodInfo method = a.EntryPoint;
if (method != null)
{
object o = a.CreateInstance(method.Name);
method.Invoke(o, null);
}
else
{
MessageBox.Show("No method found!");
}
}
}
catch (Exception ex)
{
MessageBox.Show("E^RR : " + ex.Message);
}
Note : Embedded resources could be any setup file, in this case I am using file_zilla setup as embedded resource file.
Any help is appreciated.