I want to load assemblies dynamically in my app with the AssemblyResolver
event, but I don't understand how to do it.
I've saw this tutorial and tried it myself. In tip 3 he wrote:
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
}
static void Print()
{
var mainClass = new MainClass();
mainClass.Print();
}
static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
return Assembly.LoadFile(@"path to the library");
}
Actually I don't understand how this code should compile at all...
The new MainClass()
cannot be compiled as it unknown (the type isn't loaded yet), the loading happens at runtime.
If the MainClass
was known type, it shouldn't be resolved at all...
How this code should work?