I'm having the hardest time with this. I've googled for hours, and been to many different questions on here, but I just can't get it.
static void Main(string[] args)
{
AppDomainSetup domainSetup = new AppDomainSetup { PrivateBinPath = typeof(Program).Assembly.Location };
AppDomain domain = AppDomain.CreateDomain("TempDomain", null, domainSetup);
InstanceProxy proxy = domain.CreateInstanceFromAndUnwrap(typeof(Program).Assembly.Location, typeof(InstanceProxy).ToString()) as InstanceProxy;
if (proxy != null)
{
proxy.LoadAssembly(Properties.Resources.mfX3DAu);
}
AppDomain.Unload(domain);
Console.Read();
}
public class InstanceProxy : MarshalByRefObject
{
public void LoadAssembly(byte[] buffer)
{
Assembly asm = Assembly.Load(buffer);
asm.EntryPoint.Invoke(null, null);
}
}
The resource "mfX3DAu" is a .Net Assembly obfuscated with Confuser.
It loads fine, and it is in the new AppDomain, but every time I try and invoke it I get
An unhandled exception of type 'System.ExecutionEngineException' occurred
Someone I talked to before said they got it working with this specific assembly, so it must be possible.
In .Net world, there is no DLL Main method which would get called whenever the assembly is loaded into an application domain. .Net however supports Module Initializers. Module Initializers are global functions, C# does not support global functions and thus Module Initializers cannot be defined and used using C# language. CLR supports Module Initializers and IL Code (OpCodes) can be used to write Module Initializers.
For more information, please refer to following link: Module Initializers