I'm creating a CMS-like application under MVC.
To handle backend code for plugins I use Web API, so putting my API DLLs in /bin folder enables me to access plugin service methods by a specific route - /api/{namespace}/{controller}/{id}.
I would like to load the assemblies from another location, then be able to unload them in case of new module install/upgrade/delete.
People suggest to override the DefaultAssembliesResolver to include plugin assemblies:
public class PluginAssembliesResolver : DefaultAssembliesResolver
{
public override ICollection<Assembly> GetAssemblies()
{
List<Assembly> assemblies = new List<Assembly>(base.GetAssemblies());
foreach (string assemblyPath in ModuleManager.GetAllAssemblyPaths(HttpContext.Current.Server))
{
if (File.Exists(assemblyPath))
{
assemblies.Add(Assembly.LoadFrom(assemblyPath));
}
}
return assemblies;
}
}
But in this case I am loading the assemblies into the current domain and I am not able to unload them.
Trying to load assemblies from another location throws an error (it recognizes my assembly, but tries to look for the same DLL under /bin or /bin/myPlugin folders):
AppDomain domain = AppDomain.CreateDomain("myDomain", null);
Assembly assembly = Assembly.LoadFrom(@"C:\myPluginPath\myPlugin.dll");
domain.Load(assembly.GetName());
How can I load them into a separate AppDomain?
Thank you.