-1

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.

Community
  • 1
  • 1
Ronan Thibaudau
  • 3,413
  • 3
  • 29
  • 78
  • 1
    -1: so far the post missing any kind of question. "Does not seem to work" is neither detailed explanation of a problem nor question. – Alexei Levenkov May 22 '13 at 17:05
  • +1 Alexei ! @Ronan : Please ask a question, that we can help you solving your problem... – Kooki May 22 '13 at 17:46
  • Hello, Does not work means i droped it, what i'd like is to get the framework working so sorry if it was unclear but my question is how do i get the code i pasted to work without the exception i get, as it seems to me it should work as is per the documentation & unit tests – Ronan Thibaudau May 22 '13 at 20:54
  • Actually the -1 is undeserved as i did ask in the code comment, but i see what happened, it scrolled past view :( fixing formating now, the question was about the exception in the code (where the comment is) – Ronan Thibaudau May 22 '13 at 20:57

1 Answers1

0

Ok in the end i found the culprit. Since i call GetAssemblies on the Domain, it at the same time loads them in the AppDomain (calling the resolver) AND in my current root domain (which needs to load the assemblies too as it gets the assembly objects as a return of GetAssemblies) To fix it i had to set the resolver both locally and on the remote domain, however this is a bad idea as it removes the isolation advantage of loading in another AppDomain, so i settled for not calling GetAssemblies and doing the reflection work on the Child domain and returning the results back to the original domain.

Ronan Thibaudau
  • 3,413
  • 3
  • 29
  • 78
  • Hey Ronan, I'm the author of AppDomainToolkit--and I'd be interested in understand a little more about the problems you couldn't solve with it. I'll try and play around with the above scenario and see if I can reproduce it, and if so hopefully improve ADT such that others don't have the same issue. Please reach out to me via my twitter handle if you have any additional information to pass along as necessary. Sorry for the troubles! – Jduv Feb 04 '14 at 16:56