I have an application that needs to load and execute assemblies at runtime.
The Add-In or Plug-In approach will not work in my case since the number of assemblies will be in the hundreds and the appropriate ones would be loaded and executed at runtime.
I am looking for two things:
- Sample code to load and execute assemblies whose internal structure is known to me at compile time.
- Best practices to ensure stability performance and security or authenticity of loaded assemblies.
My application code logic will look like this:
public static void Main()
{
foreach (string filename in directory.GetFiles())
{
Assembly assembly = LoadAssemblyFromFile(filename);
object instance = CreateInstanceOfClassXyzInAssembly(assembly);
instance.CallSomeMethodWithKnownInterface();
instance = null;
UnloadAssembly(assembly);
}
}