I am writing a plugin architecture. My dll plugins are in the subdirectory from which the plugin manager is launched. I load plugins into a separate AppDomain as follows:
string subDir;//initialized to the path of the module directory. AppDomainSetup setup = new AppDomainSetup(); setup.PrivateBinPath = subDir; setup.ApplicationBase = subDir; AppDomain newDomain= AppDomain.CreateDomain(subDir, null, setup); byte[] file = File.ReadAllBytes(dllPath);//dll path is a dll inside subDir newDomain.Load(file);
But. newDomain.Load returns the assembly that the current domain is trying to load. Since the DLL plugin is in a subdirectory, the current domain cannot and should not see these DLLs, and the current domain throws a FileLoadException "ex = {" Failed to load the file or assembly ... or one of its dependencies. "
The question is, can we load the assembly into a separate AppDomain without returning the loaded assembly?
I know that I can add a handler for the AssemblyResolve event in the current domain and return zero, but I would prefer not to go this route.
Thanks in advance.
Anish source share