Skip to content

Instantly share code, notes, and snippets.

@fresky
Created December 22, 2012 05:45
Show Gist options
  • Save fresky/4357669 to your computer and use it in GitHub Desktop.
Save fresky/4357669 to your computer and use it in GitHub Desktop.
AssemblyResolve example
public class MyClass
{
public MyClass()
{
Console.WriteLine("MyClass is created!");
}
}
public class Program
{
static void Main(string[] args)
{
AppDomain app = AppDomain.CurrentDomain;
app.AssemblyResolve += (sender, eventArgs) =>
{
try
{
return Assembly.ReflectionOnlyLoad(eventArgs.Name);
}
catch (Exception)
{
Console.WriteLine("Can't load user specified assembly: " + eventArgs.Name);
Console.WriteLine("Return the assembly of MyClass");
return typeof (MyClass).Assembly;
}
};
app.CreateInstance("111", "CSTest.MyClass");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment