I want to start a C# Console Application by loading it from a byte array. if I write the application to disk and start the program manually, it starts, so it means that the bytes were read correctly. I tried various snippets that I found online, for example:
or:
These codes actually work with visual application c# (Winforms), but not with those console applications.
How can i make it works?
Code
Assembly a = Assembly.Load(programma);
MethodInfo method = a.EntryPoint;
if (method != null)
{
object o = a.CreateInstance(method.Name);
method.Invoke(o, null);
}or:
Code
public static Thread RunFromMemory(byte[] bytes)
{
var thread = new Thread(new ThreadStart(() =>
{
var assembly = Assembly.Load(bytes);
MethodInfo method = assembly.EntryPoint;
if (method != null)
{
method.Invoke(null, null);
}
}));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
return thread;
}These codes actually work with visual application c# (Winforms), but not with those console applications.
How can i make it works?


