Skip to content

Instantly share code, notes, and snippets.

@DavidKarlas
Created March 2, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidKarlas/7e263d4ae4ff5d6333b6 to your computer and use it in GitHub Desktop.
Save DavidKarlas/7e263d4ae4ff5d6333b6 to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using System.Security.Policy;
class Program
{
static void Main(string[] args)
{
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
Evidence adevidence = AppDomain.CurrentDomain.Evidence;
AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence, domaininfo);
Type type = typeof(Proxy);
var value = (Proxy)domain.CreateInstanceAndUnwrap(
type.Assembly.FullName,
type.FullName);
var assembly = value.GetAssembly("C:\\Users\\David\\Documents\\Projects\\cpp534534526423463\\cpp534534526423463\\bin\\Debug\\lib2.dll");
var lal = assembly.GetTypes () [0];
var instance = Activator.CreateInstance (lal);
// AppDomain.Unload(domain);
}
}
public class Proxy : MarshalByRefObject
{
public Assembly GetAssembly(string assemblyPath)
{
try
{
return Assembly.LoadFile(assemblyPath);
}
catch (Exception)
{
return null;
// throw new InvalidOperationException(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment