I've found a few variants of this question but it seems mixing all those criterias produces it's own set of errors when you want your assembly loaded
- In another appdomain
- From another folder
- With additional dependencies
I need all this to load my third party plugins and found something that looked like a solution but didn't work here : How to Load an Assembly to AppDomain with all references recursively? I didn't manage to get any of this to work even going through all the comments i still end up with FileNotFoundExceptions on referenced assemblies. However i found a framework that could fit my needs in one of the comments : https://github.com/jduv/AppDomainToolkit But that too doesn't seem to work, here's the sample code i'm using with this framework but am still getting a file not found exception
var uploadedPluginsDirectories = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(),"UploadedModules"));
foreach(var uploadedPluginsDirectory in uploadedPluginsDirectories.GetDirectories())
{
foreach (var pluginFile in uploadedPluginsDirectory.GetFiles("*.dll")
.Where(f=>f.Name == "DeepSearch.Modules.Excel.Graphs.dll"))
{
var context = AppDomainContext.Create();
int Count = context.Domain.GetAssemblies().Count();
context.RemoteResolver.AddProbePath(pluginFile.Directory.FullName);
var load = context.LoadAssemblyWithReferences(LoadMethod.LoadFrom, pluginFile.FullName);
// This crashes complaining about FileNotFoundException on one of the assemblies referenced by the one i'm trying to load, they both are in pluginFile.Directory.FullName
Count = context.Domain.GetAssemblies().Count();
Count.ToString();
}
}
Edit: To clarify as the comments requested, I'm asking for help to get the snippet to work as, as mentioned, I'm getting an exception, i only mentioned what i tried before to list the options that failed for me but I'm looking for help on this, not on the previous options, as this seems much cleaner than working with the AppDomain & remoting API myself.