Created
December 22, 2012 05:45
-
-
Save fresky/4357669 to your computer and use it in GitHub Desktop.
AssemblyResolve example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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