Hi, simple question, probably easy for you to answer.
I have a dll named "MigrationSteps.dll" in the same output folder of my application. What I want to do, is to load this assembly in a new AppDomain and execute a method on an instance of a class inside this DLL.
Here's my code
string migrationStepsDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MigrationSteps.dll");
AppDomainSetup appDomainSetup = new AppDomainSetup() { PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory };
Evidence evidence = AppDomain.CurrentDomain.Evidence;
AppDomain appDomain = AppDomain.CreateDomain("MigrationAppDomain", evidence, appDomainSetup);
//NOT WORKING
Assembly assembly = appDomain.Load(@"C:\Output\Debug\OptimeToolbench\MigrationSteps.dll");
//WORKING
Assembly assembly = Assembly.LoadFrom(@"C:\Output\Debug\OptimeToolbench\MigrationSteps.dll"); ****works.
//This part works well
Type type = assembly.GetType("MigrationSteps.Foo");
object foo = Activator.CreateInstance(type);
MethodInfo methodInfo = type.GetMethod("HelloWorld");
methodInfo.Invoke(foo, null);
AppDomain.Unload(appDomain);
Everytime the line indicated as not working throws a
FileNotFoundException
.
Why's that ?
Thanks for you time.